質問は非常に明確です。ビューにリストビューまたはリストボックスがあります。画面を小さくする場合、テキスト (ラベルなど) を同じサイズのままにしたいと考えています。しかし、リストビューとリストボックスは小さくする必要があり、最終的にはスクロールバーが必要ですか?
どうすればいいですか?
ありがとう
ListBox には ScrollViewer が組み込まれています。
<ListBox ScrollViewer.VerticalScrollBarVisibility="Auto" />
質問は非常に明確です。
まあ、正確ではありません。しかし、これはあなたが探しているものだと思います。Double
まず、 を受け取り、その逆数を返す値コンバーターを作成します。
public class ReciprocalValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Double? d = value as Double?;
return (d == null || d == 0)
? null
: 1/d;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
を使用して任意のコンテンツ コントロールを拡大縮小しScaleTransform
、 を使用してそのReciprocalValueConverter
中に含まれる個々の要素を元の拡大縮小に保つことができるようになりました。したがって、コンテンツ コントロールのスケールが 2 倍になった場合、変更しないままにしたいコンテンツのスケールは半分になります。
LayoutTransform
この例では、各項目に を割り当てることによって、コンテンツ コントロールのスケーリングと、リスト ボックス内の項目の「スケーリング解除」の両方を示しています。
<Window x:Class="ScaleTransformDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ScaleTransformDemo="clr-namespace:ScaleTransformDemo" Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ScaleTransformDemo:ReciprocalValueConverter x:Key="Reciprocal" />
</Window.Resources>
<DockPanel>
<Slider x:Name="ScaleSlider"
Orientation="Vertical"
Minimum=".2"
Maximum="4"
Value="1" />
<DockPanel>
<DockPanel.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=ScaleSlider, Path=Value}"
ScaleY="{Binding ElementName=ScaleSlider, Path=Value}" />
</DockPanel.LayoutTransform>
<Label DockPanel.Dock="Top">
The content of this label scales with the slider.
</Label>
<Label DockPanel.Dock="Top">
<Label.LayoutTransform>
<ScaleTransform ScaleX="{Binding ElementName=ScaleSlider, Path=Value, Converter={StaticResource Reciprocal}}"
ScaleY="{Binding ElementName=ScaleSlider, Path=Value, Converter={StaticResource Reciprocal}}" />
</Label.LayoutTransform>
<Label.Content>
This label's content stays the same size.
</Label.Content>
</Label>
<Label DockPanel.Dock="Top">
The ListBox below scales with the slider, too, but the ListBoxItems don't:
</Label>
<ListBox Height="50"
DockPanel.Dock="Top">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="LayoutTransform">
<Setter.Value>
<ScaleTransform ScaleX="{Binding ElementName=ScaleSlider, Path=Value, Converter={StaticResource Reciprocal}}"
ScaleY="{Binding ElementName=ScaleSlider, Path=Value, Converter={StaticResource Reciprocal}}" />
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 2</ListBoxItem>
<ListBoxItem>Item 3</ListBoxItem>
<ListBoxItem>Item 4</ListBoxItem>
<ListBoxItem>Item 5</ListBoxItem>
<ListBoxItem>Item 6</ListBoxItem>
</ListBox>
<TextBlock DockPanel.Dock="Top" />
</DockPanel>
</DockPanel>
</Window>