1

WPFは初めてです。一連のラベルとリストボックスを含むWPFウィンドウがあります。

ウィンドウのサイズを変更するときに、一部のラベルのサイズを拡大縮小したいのですが、すべてではありません。ListBoxもスケーリングしたくありません。一部のラベルだけです。

ウィンドウのサイズが変更されたときにビューボックスを使用してサイズを変更できることは理解していますが、それをいじると、目的の効果が得られません。もちろん、すべてのサイズを変更するため、ビューボックスで全体を囲むことはできません。そのため、展開する各ラベルを囲むウィンドウ全体に、さまざまなビューボックスをドロップする必要があると考えました。しかしもちろん...私がこれを行うとき、何も拡張しません。

同じように、ラベルを展開すると、識別子であるため、それらのラベルのすぐ隣に残す必要のある他のラベルがあります。

だから...これが私がこの時点で持っているXAMLです。私が正しい道を進んでいるかどうかさえわかりません。番号が入ったラベルをウィンドウで拡大するのに役立つ情報があれば幸いです。

<Window x:Class="WpfApplication7.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfApplication7"
    Title="Window1">
    <StackPanel Orientation="Horizontal">
        <ListBox Margin="2">
            <ListBoxItem>a</ListBoxItem>
            <ListBoxItem>b</ListBoxItem>
            <ListBoxItem>c</ListBoxItem>
        </ListBox>
        <StackPanel Orientation="Vertical">
            <Label>Title</Label>
            <StackPanel Orientation="Horizontal">
                <Grid>
                    <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions>
                    <Label Grid.Row="0">A</Label>
                    <Label Grid.Row="1">B</Label>
                    <Label Grid.Row="2">C</Label>
                    <Label Grid.Row="3">D</Label>
                </Grid>
                <Grid>
                    <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions>
                    <Viewbox Grid.Row="0" Stretch="Fill">
                        <Label>1</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="1" Stretch="Fill">
                        <Label>2</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="2" Stretch="Fill">
                        <Label>3</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="3" Stretch="Fill">
                        <Label>4</Label>
                    </Viewbox>
                </Grid>
                <Grid>
                    <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions>
                    <Viewbox Grid.Row="0" Stretch="Fill">
                        <Label>5</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="1" Stretch="Fill">
                        <Label>6</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="2" Stretch="Fill">
                        <Label>7</Label>
                    </Viewbox>
                    <Viewbox Grid.Row="3" Stretch="Fill">
                        <Label>8</Label>
                    </Viewbox>
                </Grid>
                <Grid>
                    <Grid.RowDefinitions><RowDefinition/><RowDefinition/><RowDefinition/><RowDefinition/></Grid.RowDefinitions>
                    <Label Grid.Row="0">E</Label>
                    <Label Grid.Row="1">F</Label>
                    <Label Grid.Row="2">G</Label>
                    <Label Grid.Row="3">H</Label>
                </Grid>
            </StackPanel>
        </StackPanel>
    </StackPanel>
</Window>

4

1 に答える 1

2

あなたは正しい道を進んでいます。ただし、いくつかの列定義を使用する必要があり、行定義は少し不安定です。互いに埋め込まれたさまざまなレイアウトパネルを使用しているため、Viewboxの組み込みのサイズ変更に影響があります。これとまったく同じレイアウトを、単一のシンプルな5x5グリッド(スタックパネルなし)で実現できます。

これを次のXAMLで示しました。

<Window x:Class="TestWpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfApplication"
Title="Window1">
<Window.Resources>
    <Style TargetType="{x:Type Label}" x:Key="{x:Type Label}">
        <Setter Property="HorizontalAlignment" Value="Center"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
    </Style>
</Window.Resources>

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>

    <ListBox Grid.RowSpan="5" Grid.Column="0">
        <ListBoxItem>a</ListBoxItem>
        <ListBoxItem>b</ListBoxItem>
        <ListBoxItem>c</ListBoxItem>
    </ListBox>

    <Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="4">Title</Label>

    <Label Grid.Row="1" Grid.Column="1">A</Label>
    <Label Grid.Row="2" Grid.Column="1">B</Label>
    <Label Grid.Row="3" Grid.Column="1">C</Label>
    <Label Grid.Row="4" Grid.Column="1">D</Label>

    <Viewbox Grid.Row="1" Grid.Column="2">
        <Label>1</Label>
    </Viewbox>
    <Viewbox Grid.Row="2" Grid.Column="2">
        <Label>2</Label>
    </Viewbox>
    <Viewbox Grid.Row="3" Grid.Column="2">
        <Label>3</Label>
    </Viewbox>
    <Viewbox Grid.Row="4" Grid.Column="2">
        <Label>4</Label>
    </Viewbox>

    <Viewbox Grid.Row="1" Grid.Column="3">
        <Label>5</Label>
    </Viewbox>
    <Viewbox Grid.Row="2" Grid.Column="3">
        <Label>6</Label>
    </Viewbox>
    <Viewbox Grid.Row="3" Grid.Column="3">
        <Label>7</Label>
    </Viewbox>
    <Viewbox Grid.Row="4" Grid.Column="3">
        <Label>8</Label>
    </Viewbox>

    <Label Grid.Row="1" Grid.Column="4">E</Label>
    <Label Grid.Row="2" Grid.Column="4">F</Label>
    <Label Grid.Row="3" Grid.Column="4">G</Label>
    <Label Grid.Row="4" Grid.Column="4">H</Label>
</Grid>

于 2009-07-16T17:04:57.567 に答える