XAML ViewBox 强制对 ListBoxItem MouseOver 进行错误的重新缩放
XAML ViewBox forces a bad rescale on ListBoxItem MouseOver
我有以下 XAML 布局(列表框,其中项目是样式为切换按钮的单选按钮)。 ListBox 和 ToggleButton 项目缩放并很好地填充 ToggleButton 项目以适应 window 大小。这正是我想要的,但是当我将鼠标悬停在 ListBox 中的 ToggleButton 上时,样式将文本设置为粗体。这也是我想要的,但问题是它使按钮稍微变大了。当鼠标悬停在具有最长文本的 ToggleButton 项目上时,ViewBox 会刷新并重新缩放所有 ToggleButton 控件。看起来所有的 ToggleButtons 都跳跃了。如何防止 ToggleButton 的这种重新缩放仍然用 ListBox 及其 ToggleButton 项目填充完整的网格列和行?
<Viewbox Stretch="UniformToFill" Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch" Margin="5,0,0,15">
<Grid x:Name="LeftSide" Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ListBox Grid.Column="0" Grid.Row="0" Grid.RowSpan="10" ItemsSource="{Binding LeftPaneViewModelInfoItems, UpdateSourceTrigger=PropertyChanged}" Background="Transparent" SelectedItem="{Binding SelectedViewModelInfoItem}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton
Content="{Binding Text}"
GroupName="DisplayPage"
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}"
Style="{StaticResource RadioButtonToggleButtonStyle}"
>
</RadioButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Viewbox>
没有找到好的解决办法。我最终从鼠标悬停样式中删除了粗体 setter 属性。
我有以下 XAML 布局(列表框,其中项目是样式为切换按钮的单选按钮)。 ListBox 和 ToggleButton 项目缩放并很好地填充 ToggleButton 项目以适应 window 大小。这正是我想要的,但是当我将鼠标悬停在 ListBox 中的 ToggleButton 上时,样式将文本设置为粗体。这也是我想要的,但问题是它使按钮稍微变大了。当鼠标悬停在具有最长文本的 ToggleButton 项目上时,ViewBox 会刷新并重新缩放所有 ToggleButton 控件。看起来所有的 ToggleButtons 都跳跃了。如何防止 ToggleButton 的这种重新缩放仍然用 ListBox 及其 ToggleButton 项目填充完整的网格列和行?
<Viewbox Stretch="UniformToFill" Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch" Margin="5,0,0,15">
<Grid x:Name="LeftSide" Grid.Row="1" Grid.Column="0" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<ListBox Grid.Column="0" Grid.Row="0" Grid.RowSpan="10" ItemsSource="{Binding LeftPaneViewModelInfoItems, UpdateSourceTrigger=PropertyChanged}" Background="Transparent" SelectedItem="{Binding SelectedViewModelInfoItem}">
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<RadioButton
Content="{Binding Text}"
GroupName="DisplayPage"
IsChecked="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}}"
Style="{StaticResource RadioButtonToggleButtonStyle}"
>
</RadioButton>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Viewbox>
没有找到好的解决办法。我最终从鼠标悬停样式中删除了粗体 setter 属性。