样式TreeviewItem布局(MVVM)

时间:2016-08-25 12:47:37

标签: c# wpf mvvm treeview styles

我有一个TreeView,我绑定了一个ObservableCollection,其中TreeView继承了TreeViewItem。

我想设置树视图的标题样式,使每个标题前面都有一个图像。我将标题设置为ItemContainerStyle,但它没有对其布局进行处理。但它适用于ContextMenu

<TreeView.ItemContainerStyle>
     <Style TargetType="{x:Type TreeViewItem}">
          <Setter Property="ToolTip" Value="{Binding ID, Mode=TwoWay}"/> 
          <Setter Property="Header">
               <Setter.Value>
                    <StackPanel Orientation="Horizontal">
                         <Image Source="Images/Icons/Plus-48.png" Height="10" Width="10" />
                         <TextBlock Text="{Binding MachinePartName}" Margin="0,0,4,0" />
                    </StackPanel>
               </Setter.Value>
          </Setter>
          <Setter Property="ContextMenu">    
               <Setter.Value>
                     <ContextMenu>
                         <MenuItem Header="Add" Command="{Binding AddMachinePart_Command}"/>
                     </ContextMenu>
               </Setter.Value>
           </Setter>
     </Style>
</TreeView.ItemContainerStyle>

1 个答案:

答案 0 :(得分:1)

您需要使用 <OutputField name="out_1" optype="continuous" dataType="double" feature="transformedValue"> <FieldRef field="Z_DD_OCCUPATION_ID"/> </OutputField> <OutputField name="out_2" optype="continuous" dataType="double" feature="transformedValue"> <FieldRef field="Z_CH_INT_FLG_CRR"/> </OutputField> 代替:

<OutputField name="out_1" optype="continuous" dataType="double" feature="transformedValue">
    <FieldRef field="TD_SALE_FLG_00M_5"/>
</OutputField>

<OutputField name="out_2" optype="continuous" dataType="double" feature="transformedValue">
    <FieldRef field="CH_INT_FLG_CRR"/>
</OutputField>

不要忘记绑定HeaderTemplate属性。