我有一个GridControl,我使用一些单元格编辑,单元格内有几个按钮。
这是一个包含3个按钮的示例列:
xmlns:dxet="http://schemas.devexpress.com/winfx/2008/xaml/editors/themekeys"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:my="clr-namespace:MyProject.DevExpress.View"
<dxg:GridColumn Width="Auto"
AllowEditing="False"
AutoFilterCondition="Default"
FieldName="Information"
Header="Info"
ShowInColumnChooser="False"
VisibleIndex="1">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ButtonEdit Name="PART_Editor" AllowDefaultButton="False">
<dxe:ButtonEdit.Buttons>
<!-- Button Action 1 -->
<my:ButtonInfoCustom Tag="Info1">
<my:ButtonInfoCustom.Template>
<DataTemplate>
<Button x:Name="PART_Item"
Height="Auto"
Content="{Binding DataContext.RowData.Row.InfoName}"
Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle,
ThemeName=DeepBlue}}"
ToolTip="{Binding DataContext.RowData.Row.CustomTooltip}" />
</DataTemplate>
</my:ButtonInfoCustom.Template>
</my:ButtonInfoCustom>
<!-- Button Action 2 -->
<my:ButtonInfoCustom Tag="Info2">
...
问题在于主题。
如果我明确地设置主题名称 ,它就可以了:
Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle, ThemeName=DeepBlue}}"
如果我试图绑定:
Style="{DynamicResource {dxet:ButtonsThemeKey ResourceKey=ButtonStyle, ThemeName={Binding ThemeToUse}}}"
我明白了:
XamlParseException:A&#39;绑定&#39;不能在&#39; ThemeName&#39;上设置 属性类型&#39; ButtonsThemeKeyExtension&#39;。 A&#39;绑定&#39;只能是 在DependencyObject的DependencyProperty上设置。
我该怎么办?
答案 0 :(得分:0)
好吧,你不应该将任何主题名称放入你的XAML代码中。
相反,使用DevExpress内置控件时会考虑实际主题并相应地更改其外观。
选中此示例(我完全删除了Style
代码并将Button
替换为SimpleButton
):
<dxg:GridColumn Width="Auto"
AllowEditing="False"
AutoFilterCondition="Default"
FieldName="Information"
Header="Info"
ShowInColumnChooser="False"
VisibleIndex="1">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:ButtonEdit Name="PART_Editor" AllowDefaultButton="False">
<dxe:ButtonEdit.Buttons>
<!-- Button Action 1 -->
<my:ButtonInfoCustom Tag="Info1">
<my:ButtonInfoCustom.Template>
<DataTemplate>
<dx:SimpleButton x:Name="PART_Item"
Height="Auto"
Content="{Binding DataContext.RowData.Row.InfoName}" ToolTip="{Binding DataContext.RowData.Row.CustomTooltip}" />
</DataTemplate>
</my:ButtonInfoCustom.Template>
</my:ButtonInfoCustom>
<!-- Button Action 2 -->
<my:ButtonInfoCustom Tag="Info2">
...