1. 程式人生 > >wpf中:xaml中的名稱空間的引入

wpf中:xaml中的名稱空間的引入

        在xaml中如有要使用c#資料型別,那麼需要引入c#的名稱空間,如需要使用String類,則需要引入String所在的名稱空間。

<Window x:Class="Test2.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">
    <Grid>
        
        <StackPanel>
            <StackPanel.Resources>
                <sys:String x:Key="myString">
                    lasklsdsldfslfd
                </sys:String>
            </StackPanel.Resources>
            <TextBox x:Name="textBox1" Text="{Binding Path=Text[4],ElementName=textBox2, Mode=OneWay}"></TextBox>
            <TextBox x:Name="textBox2" Text="{StaticResource ResourceKey=myString}"></TextBox>
        </StackPanel>
    </Grid>
</Window>