小编Pan*_*dra的帖子

在WPF中以编程方式将用户控件/页面添加到Windows xaml

我想在Window1.xaml(主窗口)中以编程方式在我的两个用户控件AddUsers.xaml(用户控件)和Viewusers.xaml(用户控件)之间切换.

我试图通过Window1.xaml中的按钮事件切换用户控件.我在网上什么都没发现,所以任何身体都可以帮助我.

我的Window1.xaml是这样的

 <Window x:Class="SwitchUsers.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="500" Width="525">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="100" />
        <RowDefinition Height="400*" />
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" >
    <Button Content="Swithc User Control " Height="23" HorizontalAlignment="Right"     Margin="0,40,284,0" Name="btnSwittch" VerticalAlignment="Center" Width="168" />
    </StackPanel>

    <StackPanel Grid.Row="1" >
       <!--Here I want to display  two user controls by switching from button on Top -->            
    </StackPanel>
</Grid> 
Run Code Online (Sandbox Code Playgroud)

我有两个用户控件addUser.xaml和viewUser.xaml

添加用户.xaml代码:

 <UserControl x:Class="SwitchUsers.addUser"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300" Loaded="UserControl_Loaded">
     <Grid>
    <TextBlock Height="23" HorizontalAlignment="Left" Margin="29,79,0,0"  Name="textBlock1" Text=" Enter Your Name" VerticalAlignment="Top" />
    <TextBlock …
Run Code Online (Sandbox Code Playgroud)

c# wpf wpf-controls

10
推荐指数
1
解决办法
4万
查看次数

标签 统计

c# ×1

wpf ×1

wpf-controls ×1