不包含任何具体操作,仅有对各种对话框的打开;
将Grid分为两部分,内部放两个stackpanel,将这两个 stackpanel分别对应Grid的1部分和2部分;
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="23*"/>
<ColumnDefinition Width="49*"/>
</Grid.ColumnDefinitions>
<StackPanel >
<Button Content="打开windows对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="Button_Click"/>
<Button Content="打开文件对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="Open_File" />
<Button Content="打开保存对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="SaveFile_click"/>
<Button Content="打开打印对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="OpenPrint_Click" />
<Button Content="字体对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="OpenFont_Click" />
<Button Content="打开颜色对话框" Margin="5" Padding="5" Height="37" FontSize="16" Click="OpenColor_Click"/>
</StackPanel>
<StackPanel Grid.Column="1" >
<ListBox x:Name="Mylist"/>
</StackPanel>
</Grid>
打开Windows对话框
这里是放置了一个DockPanel控件,内部放置了两个<StackPanel>控件,一个TextBlock控件,这里需要注意的函数设置:DockPanel.Dock设置停靠位置,Orientation设置StackPane水平方向,FlowDirection设置绘制方向;
<DockPanel>
<StackPanel DockPanel.Dock="Top">
<TextBlock>这是一个对话框</TextBlock>
</StackPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" FlowDirection="RightToLeft">
<Button Content="Cancel" Margin="5" Padding="5" Width="100" Height="46" FontSize="22" Click="Cancel_Click" />
<Button Content="OK" Margin="5" Padding="5" Width="100" Height="46" FontSize="22" Click="Ok_click"/>
</StackPanel>
<TextBlock></TextBlock>
</DockPanel>
设置返回值:
DialogResult = false;
接收返回值:文章来源:https://www.toymoban.com/news/detail-557132.html
Window1 w1 = new Window1();
w1.ShowDialog();
Mylist.Items.Add(w1.DialogResult);
文章来源地址https://www.toymoban.com/news/detail-557132.html
打开文件对话框
Microsoft.Win32.OpenFileDialog of = new Microsoft.Win32.OpenFileDialog();
if(of.ShowDialog()==true)
{
Mylist.Items.Add(of.FileName);
}
保存文件对话框
Microsoft.Win32.SaveFileDialog SF = new Microsoft.Win32.SaveFileDialog();
if(SF.ShowDialog()==true)
{
Mylist.Items.Add(SF.FileName);
}
打印对话框
PrintDialog PD = new PrintDialog();
if (PD.ShowDialog() == true)
Mylist.Items.Add("打印");
字体对话框
System.Windows.Forms.FontDialog FD = new System.Windows.Forms.FontDialog();
if (FD.ShowDialog() == System.Windows.Forms.DialogResult.OK)
Mylist.Items.Add("字体已选择");
颜色对话框
System.Windows.Forms.ColorDialog Cd = new System.Windows.Forms.ColorDialog();
if (Cd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
Mylist.Items.Add("颜色已选择");
到了这里,关于使用WPF 打开各种对话框的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!