โหลดต่างออกข้อมูลของต้นแบบใน WPF datagrid คอลัมน์

0

คำถาม

มันเป็นไปได้ที่จะโหลดอีกข้อมูลของแม่แบบสำหรับกำหนดไว้คอลัมน์ใน WPF ข้อมูลของเส้นกริด?

ฉัน XAML ดูเหมือนนี้:

<DataGridTemplateColumn Header="Select">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <CheckBox 
                  HorizontalContentAlignment="Center"
                  Visibility="{Binding IsStarted}"
                  VerticalAlignment="Center"
                  IsChecked="{Binding IsStarted, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                  Command="{Binding DataContext.Checked,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                  CommandParameter="{Binding}"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>

เป้าหมายอยู่ที่นี่คือโหลดแยกข้อมูลของต้นแบบเมื่อตอนที่ผูกมัดหรอ IsStarted ตั้งค่าเพื่อปลอม,หรือจะพูดอีกอย่างตอนที่มองเห็นได้ถูกตั้งให้ปลอม.

ที่แรดประสงค์ที่นี่คือเมื่อบางอย่างปุ่มคือกระตุ้นซึ่งจะตั้งค่าค่าตรรกะว่า"ผิด"อีกข้อมูลของต้นแบบจะต้องเห็นเรื่องนี้เป็นของคอลัมน์แทนที่จะอยู่ในปัจจุบันที่มีอยู่รายการ.

เป็นตัวอย่างที่ตาม XAML ควรจะแสดงครั้งตรรกะที่จะตั้งค่าปลอมหลังจากการประหารชีวิตของปุ่ม

<TextBlock Visibility="{Binding IsTrue}" Text="Hello" />

นี่มันเป็นไปได้?

binding datagrid wpf xaml
2021-11-22 07:13:27
1

คำตอบที่ดีที่สุด

1

คุณอาจจะแทนที่ CheckBox ใน DataTemplate กับ ContentControl และใช้ Style กับ DataTrigger เพื่อแทนที่ของมัน ContentTemplate ดูจากค่าของคน IsStarted พารามิเตอร์:

<DataGridTemplateColumn Header="Select">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <ContentControl Content="{Binding}">
                <ContentControl.Style>
                    <Style TargetType="ContentControl">
                        <Setter Property="ContentTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <CheckBox 
                                        HorizontalContentAlignment="Center"
                                        Visibility="{Binding IsStarted}"
                                        VerticalAlignment="Center"
                                        IsChecked="{Binding IsStarted, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                        Command="{Binding DataContext.Checked,RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
                                        CommandParameter="{Binding}"/>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding IsStarted}" Value="False">
                                <Setter Property="ContentTemplate">
                                    <Setter.Value>
                                        <DataTemplate>
                                            <TextBlock Text="Some other template" />
                                        </DataTemplate>
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </ContentControl.Style>
            </ContentControl>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
2021-11-22 15:27:33

ในภาษาอื่นๆ

หน้านี้อยู่ในภาษาอื่นๆ

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................