WPF CM框架下点击不同的按钮切换到不同的界面

2016-10-28 07:30:55来源:CSDN作者:qq_32493189人点击

第七城市

1.View中加入控件

<UserControl x:Class="WinTab.View.TabControl"             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"              xmlns:cal="http://www.caliburnproject.org"             xmlns:vm="clr-namespace:WinTab.View"             xmlns:me="clr-namespace:WinTab.ViewModel"             mc:Ignorable="d"              d:DesignHeight="300" d:DesignWidth="300">    <UserControl.DataContext>        <me:TabControlViewModel></me:TabControlViewModel>    </UserControl.DataContext>    <Grid>        <DockPanel>            <Button Height="60" Width="100" DockPanel.Dock="Top" cal:Message.Attach="[Event Click]=[Action Btn1Click($view,$eventArgs)]"></Button>            <Button Height="60" Width="100" DockPanel.Dock="Bottom" cal:Message.Attach="[Event Click]=[Action Btn2Click($view,$eventArgs)]"></Button>            <StackPanel>                <ContentControl Content="{Binding ConVM}"></ContentControl>            </StackPanel>        </DockPanel>     </Grid></UserControl>

2.在对应的ViewModel中绑定不同的View

public class TabControlViewModel:PropertyChangedBase    {        public void Btn1Click(object sender,RoutedEventArgs e)        {            ConVM = new Tab1View();        }        public void Btn2Click(object sender, RoutedEventArgs e)        {            ConVM = new Tab2View();        }        private object conVM;        public object ConVM        {            get { return conVM; }            set            {                conVM = value;                NotifyOfPropertyChange(() => ConVM);            }        }    }
第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台