我有一個問題,看起來很多人以前都有過。我嘗試使用一個包含多個控件的GridView的樣式。查看不能共享多個列表視圖
我在網上搜索答案,得到了兩種解決方案:
- 更改靜態資源與DynamicResource
- 使用X:在GridView上
共享= 「假」 我想這兩個解決方案(即使在同一時間),但是當我將樣式應用到第二個控件時,錯誤仍然出現。
的樣式看起來像這樣
<Style x:Key="MyCustomStyle" TargetType="{x:Type MyUserControl}" BasedOn="{StaticResource MyUserControlBaseStyle}">
<Setter Property="Watermark" Value="{x:Static LabelResources.Caption}"/>
<Setter Property="ErrorText" Value="{Binding Converter={StaticResource FormatStringConverter}, ConverterParameter={x:Static LabelResources.Caption}}"/>
<Setter Property="LookupTemplate">
<Setter.Value>
<DataTemplate DataType="{x:Type LookupResult}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" Margin="0,0,2,0"/>
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="SuggestionsView" Value="{DynamicResource CustomGridView}"/>
</Style>
這裏GridView的
<GridView x:Key="CustomGridView" x:Shared="False">
<GridViewColumn Header="{x:Static resources:LabelResources.Name}" Width="Auto" HeaderContainerStyle="{DynamicResource GridViewHeaderStyle}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
我能做些什麼?
嗨Rachel。是不是x:shared =「false」創建GridView的新實例的目的? AdviceView基本上是一個派生自GridView的類,它帶有一些額外的功能,允許我添加動態創建的列。 – StefanG
@StefanG是的,但它只適用於對象在已編譯的ResourceDictionary中。如果它是鬆散的XAML或其他嵌套字典,它將不起作用。你的設置如何? – Rachel
我有一個ResourceDictionary與我的這個控件的所有樣式。 「編譯」是什麼意思?有沒有特別的選擇呢,還是使用ResourceDictionaries時的正常行爲? – StefanG