xaml

Image to fit grid cell size in WPF

痞子三分冷 提交于 2020-02-27 23:26:45
问题 I have a grid with 2 rows and 2 columns. At 0,0 I have a TextBlock with some text that can change due to localization, at 1,0 I have an Image. Here is the example XAML: <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"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Grid

在WPF中调用Winform控件

社会主义新天地 提交于 2020-02-27 02:42:40
1、添加两个引用: WindowsFormsIntegration.dll(负责整合WPF和Windows)、System.Windows.Forms.dll 2、在 XAML文件中添加引用(粗体部分): <Window x:Class="VideoPreview.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:winForms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" Title="MainWindow" Height="620" Width="560"> < /Window> 3、在XAML编码区实现你想添加的控件: <WindowsFormsHost Height="304" Width="540" Background="#FF00FF23" Opacity="0.2"> <winForms:PictureBox x:Name="RealPlayWnd" /> </WindowsFormsHost> 来源: https://www.cnblogs.com

WPF笔记(1.2 Navigation导航)——Hello,WPF!

点点圈 提交于 2020-02-27 02:39:30
这一节是讲导航的。看了一遍,发现多不能实现,因为版本更新了,所以很多旧的语法不支持了,比如说,不再有NavigationApplication,仍然是Application,TextBlock容器的TextWrap属性改为TextingWrap, StartupUri指向"Page1.xaml"。只要WPFApplication(不是Browser)内展示Page的页面,都会自动产生导航条。 下面我们来看Page1.xaml Example 1 - 16 . A sample navigation page <!-- Page1.xaml --> < Page x:Class = " MyNavApp.Page1 " xmlns = " http://schemas.microsoft.com/winfx/avalon/2005 " xmlns:x = " http://schemas.microsoft.com/winfx/xaml/2005 " Text = " Page 1 " > < TextBlock FontSize = " 72 " TextWrap = " Wrap " > Check out < Hyperlink NavigateUri = " page2.xaml " > page 2 </ Hyperlink > , too. </ TextBlock >

How do you bind to the property of a User Control?

心已入冬 提交于 2020-02-27 02:26:34
问题 In Windows Store Apps, you create a user control to encapsulate and reuse code-behind and layout XAML. A simple user control might look like this: <UserControl> <StackPanel> <TextBlock Text="First Name" /> <TextBox x:Name="MyTextBox" /> </StackPanel> </UserControl> Now, I want to setup binding. So I create code-behind with properties that expose the Text properties of the UI controls. Something like this: public string TextBoxText { get { return MyTextBoxText.Text; } set { MyTextBoxText.Text

How do you bind to the property of a User Control?

不羁的心 提交于 2020-02-27 02:26:17
问题 In Windows Store Apps, you create a user control to encapsulate and reuse code-behind and layout XAML. A simple user control might look like this: <UserControl> <StackPanel> <TextBlock Text="First Name" /> <TextBox x:Name="MyTextBox" /> </StackPanel> </UserControl> Now, I want to setup binding. So I create code-behind with properties that expose the Text properties of the UI controls. Something like this: public string TextBoxText { get { return MyTextBoxText.Text; } set { MyTextBoxText.Text

How do you bind to the property of a User Control?

风流意气都作罢 提交于 2020-02-27 02:24:47
问题 In Windows Store Apps, you create a user control to encapsulate and reuse code-behind and layout XAML. A simple user control might look like this: <UserControl> <StackPanel> <TextBlock Text="First Name" /> <TextBox x:Name="MyTextBox" /> </StackPanel> </UserControl> Now, I want to setup binding. So I create code-behind with properties that expose the Text properties of the UI controls. Something like this: public string TextBoxText { get { return MyTextBoxText.Text; } set { MyTextBoxText.Text

dotnetcore3.1 WPF 实现多语言

假如想象 提交于 2020-02-27 00:57:40
dotnetcore3.1 WPF 实现多语言 Intro 最近把 DbTool 从 WinForm 迁移到了 WPF,并更新到了 dotnet core 3.1,并实现了基于 Microsoft.Extensions.Localization 实现了基本的多语言支持。下面来分享一下如何来实现 服务注册 如果不熟悉如何在 WPF 中使用依赖注入,可以参考上一篇文章 dotnetcore3.1 WPF 中使用依赖注入 在应用启动前注册 Localization 服务,我这里使用的是自己自定义的基于 JSON 的多语言服务 services.AddJsonLocalization(options => options.ResourcesPathType = ResourcesPathType.CultureBased); 服务注册的最后使用了一个 ServiceLocator 模式的代码(DependencyResolver),保存了所有的注册服务,后面的 Localizer 扩展会用到 DependencyResolver.SetDependencyResolver(services); 代码文件实现方式 代码文件(如:MainWindow.xaml.cs) 中实现多语言较为简单,直接注入 IStringLocalizer 即可,获取对应的要实例化的,比如: public

Adding a Parameter to a Button_Click event in WPF

依然范特西╮ 提交于 2020-02-25 08:32:44
问题 I know it has been asked before but after about an hour of searching I am unable to figure out the simplest and easiest way to add a parameter to an event handler. By default, the template for these handlers can only accept (object sender, RoutedEventArgs e) arguments. I find it hard to believe that there isn't a clean and easy way to do this because I imagine this problem occurs quite frequently. However I am new to WPF so if someone could provide some guidance on this issue my code is below

How to Synchronize ListBox SelectedItem and the focused item in WPF?

柔情痞子 提交于 2020-02-25 07:28:45
问题 I create buttons as ListBox items. Using keyboard shortcut, the selected item/button will be changed to the button where the first character is the same with the pressed key. The problem is the focused item (dashed rectangle) will not be synchronized with selected item. This problem doesn't exist if we use keyboard arrow. The shorted code is: <ListBox x:Name="ListBoxRef" ScrollViewer.HorizontalScrollBarVisibility="Disabled" DataContext="{Binding Path=ListViewSource}"

XAML Code IsChecked Trigger On ToggleButton [duplicate]

做~自己de王妃 提交于 2020-02-24 12:57:12
问题 This question already has answers here : WPF ToggleButton IsChecked Trigger (2 answers) Closed 5 years ago . For some reason the following code will not work <ToggleButton Content="Options" x:Name="Options" Height="{Binding ElementName=Connect,Path=ActualHeight}"> <ToggleButton.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="OptionsPanel" Property="Visibility" Value="Collapsed"/> </Trigger> </ToggleButton.Triggers> </ToggleButton> <StackPanel x:Name="OptionPanel"> <