WPF(x-Key 使用)

作者:杭州车成汽车事务代理服务部 来源:www.guohuicar.com 发布时间:2017-09-15 10:46:07
WPF(x:Key 使用)

[html] view plaincopyprint?
<Window x:Class="TestOfKey.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<sys:String x:Key="myString">Hello WPF Resource!</sys:String>
</Window.Resources>

<StackPanel Background="Gray" >
<TextBox Text="{StaticResource ResourceKey=myString}" Margin="5" />
<TextBox x:Name="textBox1" Margin="5" />
<Button Content="Show" Click="ButtonClick" Margin="5" />
</StackPanel>
</Window>

<Window x:Class="TestOfKey.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<sys:String x:Key="myString">Hello WPF Resource!</sys:String>
</Window.Resources>

<StackPanel Background="Gray" >
<TextBox Text="{StaticResource ResourceKey=myString}" Margin="5" />
<TextBox x:Name="textBox1" Margin="5" />
<Button Content="Show" Click="ButtonClick" Margin="5" />
</StackPanel>
</Window>[csharp] view plaincopyprint?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestOfKey
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

private void ButtonClick(object sender, RoutedEventArgs e)
{
this.textBox1.Text = this.FindResource("myString") as string;
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:荆州SEO http://jingzhou.raoyu.net

  • 上一篇:RCP开发之comand(命令)
  • 下一篇:最后一页
  • 
    COPYRIGHT © 2015 杭州车成汽车事务代理服务部 ALL RIGHTS RESERVED.
    本站所有原创信息,未经许可请勿任意转载或复制使用 网站地图 技术支持:肥猫科技
    精彩专题:网站建设
    购买本站友情链接、项目合作请联系客服QQ:2500-38-100