How do i set a Binding Value to a TargetNullValue property in a DataGridTextColumn WPF XAML

c# datagrid entity-framework-6 wpf xaml

Accepted Answer

You cannot be bound byTargetNullValue . There is only room for a hard-coded value. You may utilize a to bind if you wish to.DataGridTemplateColumn with aTextblock and apply aDataTrigger click on it to alter the value.

Thus, default toTextblock to fasten toMunicipio , therefore if it is{x:Null} then connect it toCCodigoPostal.Municipio .

<DataGrid.Columns>
    <DataGridTemplateColumn>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Path=Municipio}">
                     <TextBlock.Style>
                         <Style TargetType="TextBlock">
                             <Setter Property="Text" Value="{Binding Path=Municipio}"></Setter>
                             <Style.Triggers>
                                 <DataTrigger Binding="{Binding Path=Municipio}" Value="{x:Null}">
                                     <Setter Property="Text" Value="{Binding Path=CCodigoPostal.Municipio}"></Setter>
                                  </DataTrigger>
                              </Style.Triggers>
                          </Style>
                      </TextBlock.Style>
                  </TextBlock>
              </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
      </DataGridTemplateColumn>
  </DataGrid.Columns>

You'd make a point to go above and above (and do it well) if you wanted to.DataTemplate Instead of including all the information, simply mention it in your resources.xaml perfectly on cue.

When using a resource, you would place theDataTemplate in theWindows.Resources .

 <Window.Resources>
        <DataTemplate x:Key="template">
            <TextBlock Text="{Binding Path=Municipio}">
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property="Text" Value="{Binding Path=Municipio}"></Setter>
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding Path=Municipio}" Value="{x:Null}">
                                <Setter Property="Text" Value="{Binding Path=CCodigoPostal.Municipio}"></Setter>
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>
        </DataTemplate>
    </Window.Resources>

Set the thenCellTemplate .

 <DataGrid x:Name="grid" Grid.Row="3">
            <DataGrid.Columns>
                <DataGridTemplateColumn CellTemplate="{StaticResource template}">
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
1
10/22/2018 2:18:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow