2011年8月10日 星期三

Expression Blend(38)-類別範例資料


本範例使用WPF專案,在設計階段繫結到範例資料
在設計階段WPF專案包含一個MyData  Class

class MyData {
       public Brush ColorName { get; set; }
   }

若有一個Button的Background要繫結到MyData的ColorName,可以
  • 建立範例資料
image
  • 選Class
image
  • 編輯資料
image
  • 設ColorName
image
  • 將Button的Background繫結到MyData的ColorName
image
image
  • 完成XAML如下
<Window
    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" mc:Ignorable="d"
    x:Class="WpfApplication3.MainWindow"
    x:Name="Window"
    Title="MainWindow"
    Width="640" Height="480">
    <Grid x:Name="LayoutRoot" d:DataContext="{d:DesignData /SampleData/MyDataSampleData.xaml}">
        <Button x:Name="button" Content="Button" Height="40" Margin="0,24,144,0" VerticalAlignment="Top" HorizontalAlignment="Right" Width="64" Background="{Binding ColorName}"/>
    </Grid>
</Window>

沒有留言:

總網頁瀏覽量