0

したがって、ビューボックス内にグリッドがあります。これで、グリッドはビューボックスに合わせてスケーリングされます。ただし、ViewModel のグリッドの高さと幅を知る必要があります。しかし、高さを何にも設定していないようですか?

<Viewbox VerticalAlignment="Top" Margin="5,20,5,0">
            <Border BorderThickness="6" BorderBrush="Black" CornerRadius="2">

                <Grid MinHeight="300" MinWidth="400" Height="{Binding Height, Mode=TwoWay}" Width="{Binding Width, Mode=TwoWay}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0" >
                    <ItemsControl ItemsSource="{Binding Viewers}">
                        <ItemsControl.ItemsPanel>
                            <ItemsPanelTemplate>
                                <Canvas />
                            </ItemsPanelTemplate>
                             </ItemsControl.ItemsPanel>
                             <ItemsControl.ItemContainerStyle>
                            <Style>
                                <Setter Property="Canvas.Left" Value="{Binding X}" />
                                <Setter Property="Canvas.Top" Value="{Binding Y}"/>
                            </Style>
                        </ItemsControl.ItemContainerStyle>
                    </ItemsControl>
                </Grid>
            </Border>
        </Viewbox>

そして私のViewModelで:

    private int _height;
    public int Height
    {
        get
        {
            return _height;
        }

        set
        {
            _height = value;
            OnPropertyChanged("Height");
        }
    }

    private int _width;
    public int Width
    {
        get
        {
            return _width;
        }

        set
        {
            _width = value;
            OnPropertyChanged("Width");
        }
    }

何か案は?

4

1 に答える 1

0

これらのプロパティは読み取り専用であるため、 /のOneWayToSourceバインディングが必要になります。これまでのところ、読み取り専用の依存関係プロパティに設定されている場合、WPF はバインディングを完全に拒否するため、適切な解決策を見てきました。ActualWidthHeight

于 2012-04-21T22:27:36.757 に答える