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
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>