■62258 / inTopicNo.1) |
UserControlから作成したWindowの破棄 |
□投稿者/ 初心者もどき (5回)-(2011/09/29(Thu) 19:20:50)
|
分類:[.NET 全般]
VS2010 FW4.0 WPF
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication2">
<Grid>
<StackPanel>
<Button Content="Exit" Name="button1" Width="100" Click="button1_Click" />
</StackPanel>
<my:UserControl1 Height="94" x:Name="userControl11" Width="220" />
</Grid>
</Window>
using System.Windows;
namespace WpfApplication2 {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
this.Visibility = Visibility.Hidden;
}
}
}
<UserControl x:Class="WpfApplication2.UserControl1"
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"
Unloaded="UserControl_Unloaded"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Button Content="SubWindowShow" Height="42" Name="button1" Width="130" Click="button1_Click" />
</Grid>
</UserControl>
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication2 {
public partial class UserControl1 : UserControl {
Window1 _Window = new Window1();
public UserControl1() {
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e) {
_Window.Show();
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e) {
if (_Window == null) _Window.Close();
}
}
}
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
WindowStyle="ToolWindow"
Closing="Window_Closing"
Topmost="True">
<Grid>
<Image Source="C:\Test.jpg"></Image>
</Grid>
</Window>
using System.Windows;
namespace WpfApplication2 {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) {
this.Visibility = Visibility.Hidden;
}
}
}
UserControlから作成したWindowの破棄が出来ません。お知恵を貸して下さい
|
|