Use DataTemplate.Triggers in WP8

被刻印的时光 ゝ 提交于 2019-12-13 00:26:58

问题


I am using an ItemsControl in WP application to show a list of objects ( bind an observable collection to this list). In WPF we can update the UI if any object properties is updated , but when it comes to WP8 , how can i do the same? Below is the syntax used in WPF , but in WP8 it shows Triggers not found

       <ItemsControl> 
            <ItemsControl.ItemTemplate> 
                <DataTemplate> 
                        <DataTemplate.Triggers> 

                </DataTemplate.Triggers> 
                </DataTemplate> 
            </ItemsControl.ItemTemplate> 
        </ItemsControl>

how can i update UI in WP8 ? What i am planning to do is based on the property of an Object set the visibility of a button in the Items.


回答1:


Rather than use a Trigger. How about using a converter (implementing IValueConverter) to set the visibility based on the property. So your xaml would look like:

<button visibility="{binding YourObjectProperty, Converter={staticresource YourVisibilityConvert}}  ... />

Then whenever the propertychanged event is fired for the property, the ui will update visibility based on the value returned by the converter.




回答2:


you could try to set behavior using Expression blend

xmlns:ec="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" x:Class="XXX_XXXX"

<Image Source="/Assets/Images/Tick.png"
                   Stretch="None"
                   HorizontalAlignment="Stretch" 
                   VerticalAlignment="Top">
                <interactivity:Interaction.Triggers>
                    <ec:DataTrigger Binding="{Binding Change}" Value="False">
                        <ec:ChangePropertyAction PropertyName="Source">
                            <ec:ChangePropertyAction.Value>

                                <BitmapImage UriSource="/Assets/Images/Close.png"/>
                            </ec:ChangePropertyAction.Value>
                        </ec:ChangePropertyAction>
                    </ec:DataTrigger>
                </interactivity:Interaction.Triggers>
            </Image>

Msdn



来源:https://stackoverflow.com/questions/18885944/use-datatemplate-triggers-in-wp8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!