WinRT XAML网格背景绑定 [英] WinRT XAML Grid Background Binding

查看:78
本文介绍了WinRT XAML网格背景绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网格背景绑定到视图模型上的画笔,但我似乎无法使其工作。 我在下面创建了一个简单的示例。 网格上的背景不绑定,但文本框却绑定。

I'm trying to bind a Grid's background to a brush on a view model, but I can't seem to get it to work.  I created a simple example below.  The Background on the grid doesn't bind, but the text box does.

 class ViewModel
    {
        public Brush Background { get { return new SolidColorBrush(new Windows.UI.Color() { G = 64, B = 80 }); } }
        public string Test { get { return "TEST"; } }
    }


<Page
    x:Class="BackgroundBrushTest.BlankPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BackgroundBrushTest"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    
    <Page.DataContext>
        <local:ViewModel />
    </Page.DataContext>
    
    <Grid Background="{Binding Background}" >
        <TextBlock Text="{Binding Test}" />
    </Grid>
</Page>







推荐答案

我将它绑定到颜色名称 - 看看它是否适合你。

I bind it to the colours name - see if that works for you.

class ViewModel
    {
        public string  { get { return "Green"; } }
        public string Test { get { return "TEST"; } }
    }


这篇关于WinRT XAML网格背景绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆