Entwickler-Ecke

WPF / Silverlight - Binding innerhalb von UserControl.Resources


alegria - Fr 18.03.11 11:18
Titel: Binding innerhalb von UserControl.Resources
Hey!

Ich bekomme es einfach nicht hin aus den Resources heraus ein Databinding zu erzeugen...

XAML:

XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
<UserControl x:Class="SilverlightApplication.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:SilverlightApplication;assembly=SilverlightApplication"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <UserControl.DataContext>
        <local:ViewModel />
    </UserControl.DataContext>

    <UserControl.Resources>
        <Style x:Name="myRedColor" TargetType="TextBlock">
            <Setter Property="Foreground" Value="Red"></Setter>
            <!--<Setter Property="Foreground" Value="{Binding vmColor}"></Setter>-->
        </Style>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot" Background="White">
        <TextBlock Text="{Binding vmText}" Style="{StaticResource myRedColor}"></TextBlock>
    </Grid>
    
</UserControl>


ViewModel.cs

C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
using System.Windows.Media;

namespace SilverlightApplication
{
    public class ViewModel
    {
        public string vmText { get { return "Lorem Ipsum..."; } }
        //public Color vmColor { get { return Colors.Red; } }
        public Brush vmColor { get { return new SolidColorBrush(Colors.Red); } }
    }
}


Kann jemand weiterhelfen???


Kha - Fr 18.03.11 12:12

Erst ab SL5 [http://forums.silverlight.net/forums/p/130096/509454.aspx].


alegria - Fr 18.03.11 16:25

wie schade... Aber danke für die Info!