Hi,
I created to 2 usercontrol for parent,child and one mainwindow. I refer the child window inside the popup control of parent window.In parent window i try to click the button popup window display.
Now i want close the popup window,when i try the click the childwindow submit button.Please help me.
MainWindow.xaml:
<window x:class="parentchild.MainWindow" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:WpfLab.Controls;assembly=WpfLab.Controls"
xmlns:local="clr-namespace:parentchild.View"
Title="MainWindow" Height="768" Width="1280">
<grid>
<local:parentview xmlns:local="#unknown">
ParentView.xaml:
<usercontrol x:class="parentchild.View.ParentView" xmlns:x="#unknown">
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:controls="clr-namespace:parentchild.View"
xmlns:vm="clr-namespace:parentchild.ViewModel"
mc:Ignorable="d"
d:DesignHeight="768" d:DesignWidth="1280">
<grid x:name="LayoutRoot" width="1280" height="768" removed="#2f3033">
<grid.resources>
<booleantovisibilityconverter x:key="BoolToVis">
<Canvas Margin="0.08,0.33,-0.081,0" VerticalAlignment="Top" Width="1280" Height="59" Visibility="{Binding canvasPlayerMain}" >
<Button Width="144" Height="44" Content="Submit" Canvas.Left="14" Canvas.Top="8" BorderBrush="#FF496E00" Foreground="Black" Command="{Binding submitCommand}">
</Button>
<stackpanel>
<popup x:name="popup" width="100" height="100" allowstransparency="True" isopen="{Binding IsPopupIsOpen}" visibility="{Binding popupVisibility}">
<grid removed="Transparent">
<controls:childview xmlns:controls="#unknown">
</Canvas>
ParentView.xaml.cs:
public partial class ParentView : UserControl
{
public RumView()
{
InitializeComponent();
this.DataContext = new ParentViewModel();
}
}
}
ParentViewModel.cs:
public class ParentViewModel : INotifyPropertyChanged
{
private readonly IEventAggregator eventAggregator=new EventAggregator();
private ParentModel currenparentModel;
private string resultMessage;
private bool _popupIsOpen;
public RumViewModel()
{
currenrumModel = new RumModel();
this.submitCommand = new DelegateCommand<object>(this.Execute, this.CanExecute);
}
public bool IsPopupIsOpen
{
get { return _popupIsOpen; }
set
{
_popupIsOpen = value;
NotifyPropertyChanged("IsPopupIsOpen");
}
}
public ParentModel currentparent
{
get
{
return currenparentModel
}
set
{
currenparentModel= value;
}
}
public Visibility popupVisibility
{
get { return this.currenrumModel.popupVisibility; }
set
{
this.currenrumModel.popupVisibility = value;
this.NotifyPropertyChanged("popupVisibility");
}
}
#region commands
public ICommand submitCommand { get; private set; }
#endregion
private bool CanExecute(object arg)
{
return true;
}
private void Execute(object arg)
{
popupVisibility = Visibility.Visible;
IsPopupIsOpen = true;
}
private void RaiseCanExecuteChanged()
{
DelegateCommand<object> tosscommand = tosscardCommand as DelegateCommand<object>;
cancelcommand.RaiseCanExecuteChanged();
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion
}
ChildWindowView.xaml:
<usercontrol x:class="parentchild.View.ChildWindowView" xmlns:x="#unknown">
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:viewModels="clr-namespace:parentchild.ViewModel"
xmlns:views="clr-namespace:parentchild.View"
mc:Ignorable="d"
d:DesignHeight="500" d:DesignWidth="500">
<grid>
<textblock horizontalalignment="Left" margin="165,106,0,0" textwrapping="Wrap" text="Reschedule Timer" verticalalignment="Top" fontsize="21.333" foreground="White" width="174" height="28">
<textblock horizontalalignment="Left" margin="37,199,0,0" textwrapping="Wrap" text="Set The Timer" verticalalignment="Top" fontsize="21.333" foreground="White" width="174" height="28">
<textbox horizontalalignment="Left" margin="252,199,0,0" textwrapping="Wrap" text="{Binding Path=setTimer}" verticalalignment="Top" width="206" height="38">
<Button Content="Submit" HorizontalAlignment="Left" Margin="252,278,0,0" VerticalAlignment="Top" Foreground="White" Width="122" Height="39" Background="Green" Command="{Binding SubmitCommand}"/>
ChildWindowView.xaml.cs:
public partial class ChildWindowView : UserControl
{
public ChildWindowView()
{
InitializeComponent();
this.DataContext = new ChildWindowViewModel();
}
}
ChildWindowViewModel.cs:
public class ChildWindowViewModel : INotifyPropertyChanged
{
private ChildWindowModel currentChildWindow;
private readonly IEventAggregator eventAggregator = new EventAggregator();
public ChildWindowViewModel()
{
currentChildWindow = new ChildWindowModel();
this.SubmitCommand = new DelegateCommand<object>(this.OnSubmit, this.CanSubmit);
}
private void RaiseCanExecuteChanged()
{
DelegateCommand<object> command = SubmitCommand as DelegateCommand<object>;
command.RaiseCanExecuteChanged();
}
public ChildWindowModel currentTimer
{
get
{
return currentTimer;
}
set
{
currentTimer = value;
}
}
public string setTimer
{
get { return this.currentChildWindow.setTimer; }
set
{
if (this.currentChildWindow.setTimer != value)
{
this.currentChildWindow.setTimer = value;
NotifyPropertyChanged("setTimer");
RaiseCanExecuteChanged();
}
}
}
public string errMessage
{
get { return this.currentChildWindow.errMessage; }
set
{
if (this.currentChildWindow.errMessage != value)
{
this.currentChildWindow.errMessage = value;
NotifyPropertyChanged("errMessage");
RaiseCanExecuteChanged();
}
}
}
public ICommand SubmitCommand { get; private set; }
private bool CanSubmit(object arg)
{
return true;
}
private void OnSubmit(object arg)
{
try
{
if (string.IsNullOrEmpty(setTimer))
{
this.errMessage = "Please enter Rescheduler Timer value";
}
}
catch (Exception ex)
{
throw ex;
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
#endregion