日期:2014-05-17  浏览次数:20945 次

WPF,控件可视状态,模板深层次该怎么写?
下面是ListBox的模板
<ControlTemplate TargetType="{x:Type ListBox}">
...
...
</ControlTemplate>

下面是ScrollViewer的模板
<ControlTemplate x:Key="ScrollViewerControlTemplate1" TargetType="{x:Type ScrollViewer}">
  ...
  ...
  <VisualStateManager.VisualStateGroups>
    ...
  </VisualStateManager.VisualStateGroups>
</ControlTemplate>


使用:
<ListBox MouseEnter="ColorChangeMouseEvent"  MouseLeave="ColorChangeMouseEvent">
   <ListBoxItem Content="ListBoxItem"/>
   <ListBoxItem Content="ListBoxItem"/>
   <ListBoxItem Content="ListBoxItem"/>
</ListBox>

private void ColorChangeMouseEvent(object sender, MouseEventArgs e) 

    if (button2.IsMouseOver) 
    {
        VisualStateManager.GoToState(这里写啥呢, "状态1", true);  
    }
    else 
    {
        VisualStateManager.GoToState(这里写啥呢, "状态2", true); 
    }
} 


问题:
ListBox模板里面,另外还有ScrollViewer的模板,要想在ListBox中使用ScrollViewer状态,GoToState方法的第一个参数该怎么写呢?似乎不能写啊

------解决方案--------------------
帮顶
------解决方案--------------------
引用:
帮顶
顶一个.........
------解决方案--------------------
看下这个例子:

<Window.Resources>
<ControlTemplate x:Key="ListBoxTemplate" TargetType="{x:Type ListBox}">
<ScrollViewer x:Name="scrollViewer" Template="{DynamicResource ScrollViewerTemplate}">
<ItemsPresenter />