System.Windows.Media.TileBrush(ViewPort)加倍

时间:2015-10-12 11:24:56

标签: c# wpf mvvm media

我正在用MVVM模式编写WPF应用程序。介于两者之间(在ListBox中)我定义了ViewPort(短版本):

<ListBox>
<ListBox.Template>
    <ControlTemplate>
        <Border>
            <Border.Background>
            </Border.Background>

            <ScrollViewer>
                <Border>
                    <Border.Background>
                        <VisualBrush 
                            TileMode="Tile" 
                            Viewport="0,0,36,36" 
                            ViewportUnits="Absolute" 
                            Viewbox="0,0,20,20" 
                            ViewboxUnits="Absolute">
                        </VisualBrush>
                    </Border.Background>
                </Border>
            </ScrollViewer>

        </Border>
    </ControlTemplate>
</ListBox.Template>

我喜欢在C#类中更改ViewPort的数量,但数字来自使用双变量的计算。那么问题是如何从double(4个数字)改为TileBrush?

我已经为TileBrush定义了get / set:

private System.Windows.Media.TileBrush _gridsquaresize;
    public System.Windows.Media.TileBrush GridSquareSize
    {
        get { return _gridsquaresize; }
        set
        {
            _gridsquaresize = value;
            NotifyPropertyChanged("GridSquareSize");
        }
    }

1 个答案:

答案 0 :(得分:1)

您可以按如下方式设置Viewport

  GridSquareSize.Viewport = new Rect(1,1,100,100);

请参阅documentation了解详情