Нулевое значение Binding - PullRequest
       49

Нулевое значение Binding

0 голосов
/ 18 апреля 2020

Я использую Dev Express Datagrid в моем C# WPF-приложении. У меня есть столбец текстового поля в сетке. Мне нужно иметь возможность динамически изменять значение NullText из ViewModel. Я попытался NullText = "{Binding NullText}" (подробности кода ниже), но, похоже, не работает.

Есть идеи, где я здесь не так?

Спасибо.

xaml:
<dxe:TextEdit HorizontalAlignment="Left" VerticalAlignment="Top" Margin="5" 
                                      Width="215" FontSize="12" Text="{Binding RowData.Row.Name,Mode=TwoWay,  
                        UpdateSourceTrigger=PropertyChanged}"  NullText={Binding NullText}                                     
                                      ShowNullText="False">
                                                    <dxe:TextEdit.Resources>
                                                        <VisualBrush x:Key="NullTextBrush" AlignmentX="Left" Stretch="None">
                                                            <VisualBrush.Visual>
                                                                <Border BorderThickness="2" BorderBrush="Transparent">
                                                                    <TextBlock Opacity="0.6" Text="{Binding Path=NullText, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dxe:TextEdit}}}" 
                                                       FontSize="{Binding Path=FontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dxe:TextEdit}}}" />
                                                                </Border>
                                                            </VisualBrush.Visual>
                                                        </VisualBrush>
                                                    </dxe:TextEdit.Resources>
                                                    <dxe:TextEdit.Style>
                                                        <Style TargetType="{x:Type dxe:TextEdit}">
                                                            <Style.Triggers>
                                                                <Trigger Property="Text" Value="{x:Null}">
                                                                    <Setter Property="Background" Value="{StaticResource NullTextBrush}" />
                                                                    <Setter Property="ToolTip" Value="{x:Null}"/>
                                                                </Trigger>
                                                                <Trigger Property="Text" Value="">
                                                                    <Setter Property="Background" Value="{StaticResource NullTextBrush}" />
                                                                    <Setter Property="ToolTip" Value="{x:Null}"/>
                                                                </Trigger>
                                                            </Style.Triggers>
                                                        </Style>
                                                    </dxe:TextEdit.Style>
                                                </dxe:TextEdit>



ViewModel:
    public class myVM{
    private string _nullText = null;


public myVM()
{
this.NullText = "input value(s)";

}
    public String NullText
            {
                get { return _nullText; }
                set
                {
                    _nullText = value;
                    RaisePropertyChangedEvent("NullText");
                }
            }


    public void RaisePropertyChangedEvent([CallerMemberName] string propertyName="")
            {
                if (PropertyChanged != null)
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
}
...