下面是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方法的第一个参数该怎么写呢?似乎不能写啊
<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方法的第一个参数该怎么写呢?似乎不能写啊
解决方案 »
- C#中有没有类似WaitForSingleObject函数的功能?
- 类型化DataSet 高手帮新手看看哪错了
- 关于WPF ICollectionView Filter的问题
- checkbox 怎么处理
- ToolStrip 中怎么没有时间控间dateTimePicker
- 如何用程序读取web页面上的内容?挑战不可能的任务
- 在C#中,Bezier曲线的两个控制点坐标如何得到?
- .net中的引用无法使用的问题
- C# 怎么实现另存为功能
- 网上书店网站,怎么实现按作者实现模糊查询?查询出来的内容是不是要用GIRDVIEW显示啊?
- C# 线程池 运行就无响应,但是程序一直在执行..球高人指点
- 请教一个程序的框架设计
<ControlTemplate x:Key="ListBoxTemplate" TargetType="{x:Type ListBox}">
<ScrollViewer x:Name="scrollViewer" Template="{DynamicResource ScrollViewerTemplate}">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate> <ControlTemplate x:Key="ScrollViewerTemplate" TargetType="{x:Type ScrollViewer}">
<Grid x:Name="grid" Background="white">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="VisualStateGroup">
<VisualState x:Name="state1">
<Storyboard>
<ColorAnimation Storyboard.TargetName="grid"
Storyboard.TargetProperty="Background.Color"
To="Blue" />
</Storyboard>
</VisualState>
<VisualState x:Name="state2">
<Storyboard>
<ColorAnimation Storyboard.TargetName="grid"
Storyboard.TargetProperty="Background.Color"
To="Green" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
Content="{TemplateBinding Content}" />
</Grid>
</ControlTemplate>
</Window.Resources>
<Grid>
<ListBox x:Name="listbox1" Template="{DynamicResource ListBoxTemplate}"
MouseEnter="ColorChangeMouseEvent" MouseLeave="ColorChangeMouseEvent">
<ListBoxItem Content="ListBoxItem" />
<ListBoxItem Content="ListBoxItem" />
<ListBoxItem Content="ListBoxItem" />
</ListBox>
</Grid>
private void ColorChangeMouseEvent(object sender, MouseEventArgs e)
{
var scrollViewer = listbox1.Template.FindName("scrollViewer", listbox1) as ScrollViewer;
var grid = scrollViewer.Template.FindName("grid", scrollViewer) as Grid;
if (listbox1.IsMouseOver)
{
VisualStateManager.GoToElementState(grid, "state1", true);
}
else
{
VisualStateManager.GoToElementState(grid, "state2", true);
}
}
Background并没有指定为SolidColorBrush,请问下,这个问题该怎么处理。
你的思路是正确