WPF绑定转换

WPF绑定转换
WPF绑定转换_第1张图片
前台代码

<Window x:Class="BindConversion.MainWindow"
        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:BindConversion"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <StackPanel Width="300" Height="300" Name="Page1">
        <StackPanel.Resources>
            <local:MyData x:Key="MyDataSource"/>
            <local:MyConverter x:Key="MyConverterReference"/>
            <Style TargetType="TextBlock">
                "FontSize" Value="15"/>
                "Margin" Value="3"/>
            Style>
        StackPanel.Resources>

        <StackPanel.DataContext>
            <Binding Source="{StaticResource MyDataSource}"/>
        StackPanel.DataContext>

        <TextBlock Text="Unconverted data:"/>
        <TextBlock Text="{Binding Path=TheDate}"/>
        <TextBlock Text="Converted data:"/>
        <TextBlock Name="myconvertedtext"
    Foreground="{Binding Path=TheDate,
                         Converter={StaticResource MyConverterReference}}">
            <TextBlock.Text>
                <Binding Path="TheDate"
               Converter="{StaticResource MyConverterReference}"/>
            TextBlock.Text>
        TextBlock>

    StackPanel>
Window>

后台代码

using System.Windows;

namespace BindConversion
{
    /// 
    ///     Interaction logic for MainWindow.xaml
    /// 
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
    }
}

你可能感兴趣的:(WPF软件开发,wpf,c#)