求教点击ListBoxItem后,弹出确认窗,确认后才让 IsSelected=true
wpf吧
全部回复
仅看楼主
level 3
如题,我使用ListBox做菜单栏,假设原来的选中项为ListBoxItem_0,点击某个ListBoxItem_1后,若有后台进程在运行,则弹出确认窗口“有操作正在进行,确定离开当前页面?”,用户点“确定”,则关闭后台进程,执行ListBoxItem_1的选中事件,ListBoxItem_1外观变为选中状态,ListBoxItem_0变为未选中状态;但如果点了“取消”,则留在当前位置,ListBoxItem_1的选中事件不执行,但是ListBoxItem_1的外观仍然变为了选中状态,ListBoxItem_0变为未选中状态。怎样才能实现 点了“取消”后,ListBox的选中项不变,使ListBoxItem_0 仍旧为选中状态。
ListBox的选择模式为单选模式;
ListBoxItem的Style定义如下:
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="contentPresenter"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="Image/btb.png">
</ImageBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2017年02月20日 08点02分 1
level 3
[]
2017年02月20日 09点02分 2
level 13
1,正确的思路应该是如果有后台或者其他原因不能操作,那选择框就置于不可操作的灰色状态,何必弹窗确认?
2,返回原先状态是2段C#事件处理程序,而不是WPF页面UI设定。选择前事件中保存状态,选择后事件中判断弹窗后返回原状态。
2017年02月20日 23点02分 3
感谢~~~改思路重新写了~~~
2017年02月21日 05点02分
1