zoukankan      html  css  js  c++  java
  • wp7 绑定

    <Grid>
    <TextBlock Text="{Binding Source}" />
    </Grid>

    public partial class Page : UserControl
    {
    public Page()
    {
    InitializeComponent();

    this.DataContext = App.Current.Host;
    }
    }

    <StackPanel BindingValidationError="StackPanel_BindingValidationError" >
    <StackPanel.Resources>
    <my:Bills x:Name="MyBills"/>
    </StackPanel.Resources>
    <TextBox x:Name="MyTextBox" Width="50" Margin="10">
    <TextBox.Text>
    <Binding Mode="TwoWay" Source="{StaticResource MyBills}"
    Path="Amount" NotifyOnValidationError="true"
    ValidatesOnExceptions="true"/>
    </TextBox.Text>
    </TextBox>
    <Button Height="50" Width="150" Content="Click To Update Source"/>
    </StackPanel>

    private void StackPanel_BindingValidationError(object sender,
    ValidationErrorEventArgs e)
    {
    if (e.Action == ValidationErrorEventAction.Added)
    {
    MyTextBox.Background = new SolidColorBrush(Colors.Red);

    }
    else if (e.Action == ValidationErrorEventAction.Removed)
    {
    MyTextBox.Background = new SolidColorBrush(Colors.White);
    }
    }

    public class Bills
    {
    private double _Amount;
    public double Amount
    {
    get { return _Amount; }
    set
    {
    if (value < 0)
    throw new Exception("Amount must be greater than zero.");
    _Amount = value;
    }
    }

    }

  • 相关阅读:
    网络流 讲解
    二分图判定 【模板】
    POJ——T3352 Road Construction
    shell脚本编写-自动部署及监控
    万能头文件
    1284 2 3 5 7的倍数(容斥原理)
    1289 大鱼吃小鱼(栈)
    1305 Pairwise Sum and Divide(数学 ,规律)
    博客达人
    Prim算法---最小生成树
  • 原文地址:https://www.cnblogs.com/androllen/p/3107712.html
Copyright © 2011-2022 走看看