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> </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 Brush vmColor { get { return new SolidColorBrush(Colors.Red); } } } } |
Kann jemand weiterhelfen???