如何将图标从DevExpress图标库添加到ButtonEdit

时间:2016-05-26 11:42:25

标签: wpf devexpress devexpress-wpf

我有ButtonEdit的以下模板:

<dxg:GridControl.Columns>
            <dxg:GridColumn Width="100"
                            AllowEditing="False"
                            AutoFilterCondition="Default"
                            FieldName="Information"
                            Header="Info"
                            ShowInColumnChooser="False"
                            SortOrder="Ascending"
                            VisibleIndex="0">
            <dxg:GridColumn.CellTemplate>
                    <DataTemplate>
                        <dxe:ButtonEdit x:Name="PART_Editor" AllowDefaultButton="False">
                            <my:ButtonInfoCustom ContentTemplate="{StaticResource MyDataTemplate}" 
                                            DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type dxg:GridControl}}}"
                                                  GlyphKind="Custom"
                                                  IsEnabled="{Binding}"
                                                  Tag="Info1"
                                                  ToolTip="Action 1" />
                        </dxe:ButtonEdit>
                    </DataTemplate>

我可以使用Image添加DataTemplate,但这些图片是不同的资源:

<DataTemplate x:Key="MyDataTemplate">
        <Image Source="/Assembly1;component/Icons/main_icon.png" />
</DataTemplate>

我打算使用图标库中的Glyph,如下所示:

<dx:SimpleButton x:Name="btn1"
                     Width="Auto"
                     Height="25"
                     HorizontalAlignment="Left"
                     Content="Add info"
                     Glyph="{dx:DXImageOffice2013 Image=Add_16x16.png}" />

如何为Glyph添加ButtonEdit

1 个答案:

答案 0 :(得分:1)

好吧,您可以将 ContentTemplate 更改为 DataTemplate ,只需将具有Glyph属性的控件放入其中:

<dxe:ButtonEdit Name="PART_Editor" AllowDefaultButton="False">
       <my:ButtonInfoCustom>
           <my:ButtonInfoCustom.Template>
                <DataTemplate>
                    <dx:SimpleButton x:Name="PART_Item" Width="Auto" Height="Auto" 
                             Glyph="{dx:DXImageOffice2013 Image=Cancel_16x16.png}"  
                             IsEnabled="{Binding IsThisButtonEnabled}"
                             Tag="Info1" ToolTip="Action 1" />
                </DataTemplate>
           </my:ButtonInfoCustom.Template>
       </my:ButtonInfoCustom>
 </dxe:ButtonEdit>