在我的WPF應用程序的其中一個屏幕上,我列出了一些有用的提示以顯示用戶。這些提示消息中的每一個都包含複雜的標記,因此我希望將消息定義保留在XAML中。我應該只顯示其中的一個提示。XAML在多個選項中切換可見性
如何根據我的枚舉切換這些消息的可見性?
目前我在做什麼看起來像這樣:
<ContentControl Grid.Row="1">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}">
<Setter Property="Visibility" Value="Collapsed"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Suggestion}" Value="AddDescription">
<Setter Property="Visibility" Value="Visible"/>
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
<Border Style="{StaticResource SuggestBox}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Image Style="{StaticResource SuggestImage}"/>
<TextBlock Grid.Column="1" Style="{StaticResource SuggestMessage}">
You can add a description to this bookmark. Adding a description will make it easier to find.
<Hyperlink Command="{Binding EditCommand}">Add a description.</Hyperlink>
</TextBlock>
</Grid>
</Border>
</ContentControl>
在上面的代碼,建議是對應於尖端應該被顯示的值枚舉。我只向一個提示展示了XAML。每個附加提示都有其自己的內容控件,其樣式觸發器綁定到Suggestion枚舉的不同值。
這看起來像許多XAML來支持簡單的可見性切換操作。當然有更簡單或更好的方法?
(請注意,我不能直接應用的可視性,觸發了Border元素的原因是Border元素已經有一個樣式集。顯然,WPF不允許你的風格結合起來。)
UPDATE:剛剛意識到這與WPF Visibility of a UI element based on combo selection和How to hide/show items in a stack panel?的問題基本相同,但在不同的上下文中。這些問題的答案看起來和我的XAML一樣醜陋。
我認爲這可能有效。我需要傳遞我正在尋找的作爲ConverterParameter的枚舉值,並將其與建議的當前值進行比較。 – dthrasher 2011-03-07 02:42:47
這聽起來對我很好。 – 2011-03-07 02:50:44