开发者

DataTrigger does not work as expected

开发者 https://www.devze.com 2022-12-12 12:54 出处:网络
I have a ComboBox bound to a ViewModel property called Property. Property is a TypeDescriptor. When user changes the value in the ComboBox, the Property is updated.

I have a ComboBox bound to a ViewModel property called Property.

Property is a TypeDescriptor.

When user changes the value in the ComboBox, the Property is updated.

On the UI i would like to either hide or make visible different controls: textbox, combobox, date picker etc.

Problem is, the DataTrigger is not working as e开发者_JAVA百科xpected.

<Style x:Key="textboxStyle"
               TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Path=Property.PropertyType}"
                             Value="{x:Type Type={x:Type sys:String}}">
                    <Setter Property="Visibility"
                            Value="Visible" />
                </DataTrigger>
            </Style.Triggers>
        </Style>


You might need to write a Converter which gets invoked when the value of 'Property' changes. The converter can be a 'TypeDescriptior to Visibility converter. The reason why the above doesnt work is because 'PropertyType' doesnt trigger INotifyPropertyChanged.

0

精彩评论

暂无评论...
验证码 换一张
取 消