wpf-controls 相关问题

WPF控件包括UserControls,它是其他控件的复合集合,以及CustomControls,它们是使用WPF样式和模板构建的控件。

我可以在WPF中使用NotifyIcon吗?

我想使用 WPF 最小化应用程序到系统托盘。 “NotifyIcon”是实现此结果的唯一方法吗?如果是,在 WPF 中使用“NotifyIcon”需要哪个命名空间? 如果可能的话...

回答 3 投票 0

在 WPF 应用程序中使用 FLAUI Inspect 工具检查时,如果数据不可见,如何从列表元素中检索数据?

这个问题已经解决了。滚动下方寻找答案 我正在研究 UI 自动化,并且是 FLAUI 的新手。在这里,我希望提取用橙色笔注释的数据。该框突出显示...

回答 1 投票 0

如何修复DataGrid滚动条与ColumnHeader相交的空白点?

我正在使用 WPF DataGrid 来显示一些数据,当我有足够的行时,会出现滚动条。在滚动条的顶部,与 DataGrid ColumnHeader 相交的地方,有一个空白方块,我不知道...

回答 1 投票 0

Powershell v5 - 引用 WPF 对象时的变量名称替换

我有 5 个按钮,它们将触发文件选择对话框,以使用所选文件路径填充 5 个文本字段。每个文件选择一个按钮即可填充单个 WPF 表单文本字段。 我不想做...

回答 1 投票 0

如何让DataGridTextColumn填满所有剩余空间

我读过很多关于类似问题的帖子,但不知道如何摆脱右侧的额外空间。中间一列(应该是最右边的一列,带有“240”和...

回答 1 投票 0

如何使我的控件可聚焦?

我有控制 公共类 FocusTestControl :控制 { 公共 FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } 这是它的默认样式 <question vote="0"> <p>我有一个控制</p> <pre><code>public class FocusTestControl : Control { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); } } </code></pre> <p>这是它的默认样式</p> <pre><code> &lt;Style TargetType=&#34;local:FocusTestControl&#34;&gt; &lt;Setter Property=&#34;Focusable&#34; Value=&#34;True&#34; /&gt; &lt;Setter Property=&#34;Template&#34;&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;Grid&gt; &lt;Border Background=&#34;AliceBlue&#34; /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>我将此控件放在窗口上:</p> <pre><code>&lt;Window x:Class=&#34;MakeWpfControlFocusable.MainWindow&#34; xmlns=&#34;http://schemas.microsoft.com/winfx/2006/xaml/presentation&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2006/xaml&#34; xmlns:local=&#34;clr-namespace:MakeWpfControlFocusable&#34; Title=&#34;MainWindow&#34; Height=&#34;350&#34; Width=&#34;525&#34;&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height=&#34;35&#34; /&gt; &lt;/Grid.RowDefinitions&gt; &lt;local:FocusTestControl /&gt; &lt;StackPanel Grid.Row=&#34;1&#34; Orientation=&#34;Horizontal&#34;&gt; &lt;TextBlock Text=&#34;Focused element: &#34; /&gt; &lt;TextBlock Text=&#34;{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=KeyboardFocusedElement}&#34; /&gt; &lt;TextBox Text=&#34;Text&#34; /&gt; &lt;/StackPanel&gt; &lt;/Grid&gt; </code></pre> <p></p> <p>但是单击控件并不会使其聚焦(我的意思是 KebordFocus)</p> <p>实际上,我的任务是处理 KeyDown 和 KeyUp 事件。但当元素没有键盘焦点时这是不可能的。</p> </question> <answer tick="true" vote="1"> <p>可以通过按 Tab 键盘键来设置键盘焦点。但点击 <pre><code>Control</code></pre> 时并未设置。我已订阅 <pre><code>MouseDown</code></pre> 事件并在处理程序中手动设置焦点。</p> <pre><code>public class FocusTestControl : Control, IInputElement { public FocusTestControl() { DefaultStyleKey = typeof(FocusTestControl); MouseDown += FocusTestControl_MouseDown; } void FocusTestControl_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) { Keyboard.Focus(this); } } </code></pre> </answer> </body></html>

回答 0 投票 0

标签内容上的 WPF StringFormat

我想将字符串绑定格式化为 Amount is X,其中 X 是绑定到标签的属性。 我见过很多例子,但以下不起作用: 我想将字符串绑定格式设置为 Amount is X,其中 X 是绑定到标签的属性。 我见过很多例子,但以下不起作用: <Label Content="{Binding Path=MaxLevelofInvestment, StringFormat='Amount is {0}'}" /> 我也尝试过这些组合: StringFormat=Amount is {0} StringFormat='Amount is {}{0}' StringFormat='Amount is \{0\}' 我什至尝试将绑定属性的数据类型更改为 int、string和 double。似乎什么都不起作用。这是一个非常常见的用例,但似乎不受支持。 这不起作用的原因是 Label.Content 属性的类型为 Object,并且 Binding.StringFormat 仅在绑定到 String 类型的属性时使用。 发生的事情是: Binding 正在对您的 MaxLevelOfInvestment 值进行装箱并将其存储为 Label.Content 属性作为装箱的十进制值。 标签控件有一个包含 ContentPresenter 的模板。 由于未设置 ContentTemplate,因此 ContentPresenter 会查找为 DataTemplate 类型定义的 Decimal。当它找不到时,它会使用默认模板。 ContentPresenter 使用的默认模板通过使用标签的 ContentStringFormat 属性来呈现字符串。 有两种可能的解决方案: 使用 Label.ContentStringFormat 而不是 Binding.StringFormat,或者 使用 String 属性(例如 TextBlock.Text)而不是 Label.Content 这里是如何使用Label.ContentStringFormat: <Label Content="{Binding Path=MaxLevelofInvestment}" ContentStringFormat="Amount is {0}" /> 以下是如何使用 TextBlock: <TextBlock Text="{Binding Path=MaxLevelofInvestment, StringFormat='Amount is {0}'}" /> 注意:为了简单起见,我在上面的解释中省略了一个细节:ContentPresenter实际上使用了自己的Template和StringFormat属性,但在加载过程中,它们会自动模板绑定到ContentTemplate和ContentStringFormat属性Label,所以看起来 ContentPresenter 实际上正在使用 Label 的属性。 制作一个通用的StringFormatConverter : IValueConverter。将格式字符串传递为 ConverterParameter. Label Content="{Binding Amount, Converter={...myConverter}, ConverterParameter='Amount is {0}'" 此外,当格式字符串中需要多个对象时,请使用 StringFormatMultiConverter : IMultiValueConverter,例如 Completed {0} tasks out of {1}。 我刚刚检查过,由于某种原因它不适用于 Label,可能是因为它在内部使用 ContentPresenter 来表示 Content 属性。您可以使用 TextBlock 来代替,这样就可以了。如果您需要继承样式、行为等,您也可以将下面的 TextBlock 摘录放在 Label 的内容中。 <TextBlock Text="{Binding Path=MaxLevelofInvestment, StringFormat='Amount is \{0\}'} /> 尝试使用转换器...... <myconverters:MyConverter x:Key="MyConverter"/> <Label Content="{Binding Path=MaxLevelofInvestment, Converter={StaticResource MyConverter"} /> public class MyConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { return String.Format("Amount is {0}", value); } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { return value; } }

回答 4 投票 0

如何检查WPF PasswordBox中PasswordChanged事件的来源?

我使用的是密码框,每次从 UI 更改密码时都需要执行一些操作。此密码框是 WPF 窗口中页面的一部分,当页面更改/卸载时,

回答 1 投票 0

WPF自定义控件路径,可点击背景

我想创建一个按钮或具有以下形式/路径的东西: 我想创建一个按钮或具有以下形式/路径的东西: <Viewbox Stretch="Uniform" x:Name="vboxSilo" > <Viewbox.ContextMenu> <ContextMenu> <MenuItem Header="T1"></MenuItem> </ContextMenu> </Viewbox.ContextMenu> <Path x:Name="pathSilo" Stretch="Uniform" Stroke="Black" Fill="Black" Data="M117.244 16.121 C 115.736 18.039,115.624 19.202,115.609 33.113 L 115.592 48.047 65.763 74.807 C 38.357 89.525,15.512 101.988,14.998 102.502 C 13.090 104.410,13.708 382.458,15.625 384.375 C 17.179 385.929,18.229 385.938,199.943 385.938 L 382.699 385.938 384.344 383.846 L 385.989 381.755 385.755 306.307 L 385.522 230.859 383.759 224.609 C 375.298 194.617,354.402 176.774,320.508 170.603 L 318.750 170.283 318.750 137.351 C 318.750 107.891,318.615 104.270,317.465 103.000 C 316.759 102.220,293.739 89.536,266.309 74.814 L 216.437 48.047 216.422 32.617 C 216.401 11.508,223.333 14.063,166.072 14.063 L 118.863 14.063 117.244 16.121 M204.688 35.938 L 204.688 46.094 166.016 46.094 L 127.344 46.094 127.344 35.938 L 127.344 25.781 166.016 25.781 L 204.688 25.781 204.688 35.938 M245.938 77.068 C 266.434 88.088,284.609 97.928,286.328 98.935 L 289.453 100.766 166.016 100.766 L 42.578 100.766 83.203 78.916 L 123.828 57.066 166.250 57.049 L 208.672 57.031 245.938 77.068 M62.500 243.359 L 62.500 374.219 44.141 374.219 L 25.781 374.219 25.781 243.359 L 25.781 112.500 44.141 112.500 L 62.500 112.500 62.500 243.359 M116.406 123.828 L 116.406 135.156 95.313 135.156 L 74.219 135.156 74.219 123.828 L 74.219 112.500 95.313 112.500 L 116.406 112.500 116.406 123.828 M307.813 141.323 C 307.813 172.904,308.094 171.094,303.186 171.094 C 279.697 171.094,251.388 195.700,242.808 223.573 L 241.046 229.297 240.812 302.148 L 240.579 375.000 184.352 375.000 L 128.125 375.000 128.125 243.750 L 128.125 112.500 217.969 112.500 L 307.813 112.500 307.813 141.323 M116.406 157.422 L 116.406 168.750 95.313 168.750 L 74.219 168.750 74.219 157.422 L 74.219 146.094 95.313 146.094 L 116.406 146.094 116.406 157.422 M116.406 191.797 L 116.406 203.125 95.313 203.125 L 74.219 203.125 74.219 191.797 L 74.219 180.469 95.313 180.469 L 116.406 180.469 116.406 191.797 M327.023 183.586 C 350.979 189.613,369.816 209.984,373.808 234.180 L 374.356 237.500 313.350 237.500 L 252.344 237.500 252.344 235.672 C 252.344 229.014,257.593 215.950,263.694 207.422 C 277.988 187.441,303.773 177.736,327.023 183.586 M116.406 226.172 L 116.406 237.500 95.313 237.500 L 74.219 237.500 74.219 226.172 L 74.219 214.844 95.313 214.844 L 116.406 214.844 116.406 226.172 M116.406 260.547 L 116.406 271.875 95.313 271.875 L 74.219 271.875 74.219 260.547 L 74.219 249.219 95.313 249.219 L 116.406 249.219 116.406 260.547 M375.000 311.719 L 375.000 374.219 313.281 374.219 L 251.563 374.219 251.563 311.719 L 251.563 249.219 313.281 249.219 L 375.000 249.219 375.000 311.719 M350.781 277.344 C 349.408 278.717,349.219 279.948,349.219 287.500 C 349.219 297.374,350.132 299.219,355.021 299.219 C 359.691 299.219,360.938 296.645,360.938 287.004 C 360.938 277.642,359.966 275.781,355.078 275.781 C 353.385 275.781,351.749 276.376,350.781 277.344 M97.754 283.594 L 116.406 283.594 116.406 294.922 L 116.406 306.250 95.313 306.250 L 74.219 306.250 74.219 294.434 L 74.219 282.617 76.660 283.105 C 78.003 283.374,87.495 283.594,97.754 283.594 M351.355 309.371 L 349.219 311.051 349.219 332.695 C 349.219 357.424,349.304 357.813,354.732 357.813 C 360.903 357.813,360.938 357.675,360.938 333.290 C 360.938 314.059,360.799 311.725,359.570 310.245 C 357.484 307.733,353.919 307.353,351.355 309.371 M116.406 328.906 L 116.406 340.625 95.313 340.625 L 74.219 340.625 74.219 328.906 L 74.219 317.188 95.313 317.188 L 116.406 317.188 116.406 328.906 M116.406 363.281 L 116.406 375.000 95.313 375.000 L 74.219 375.000 74.219 363.281 L 74.219 351.563 95.313 351.563 L 116.406 351.563 116.406 363.281 " /> </Viewbox> 它可以工作,但是上下文菜单仅在您单击轮廓或路径时才会触发... 如何使背景也可点击? 我还希望能够更改形状内的背景颜色... 我尝试了几种容器类型并使用了 Clip 属性,但不起作用。 我还尝试了几种容器类型,但背景和按钮最终从所需的形状中突出。 提前致谢 如果您希望路径可扩展,那么需要将其放置在固定大小的容器中,否则它将尝试占用尽可能多的屏幕空间。 要使对象可点击,背景需要设置为默认空值以外的值。要与父背景保持相同,请使用透明。 此布局无需使用 ViewBox 控件。 <Grid Width="50" Height="50" Background="Transparent"> <Grid.ContextMenu> <ContextMenu> <MenuItem Header="T1"></MenuItem> </ContextMenu> </Grid.ContextMenu> <Path x:Name="pathSilo" Stretch="Uniform" Stroke="Black" Fill="Black" Data="M117.244 16.121 C 115.736 18.039,115.624 19.202,115.609 33.113 L 115.592 48.047 65.763 74.807 C 38.357 89.525,15.512 101.988,14.998 102.502 C 13.090 104.410,13.708 382.458,15.625 384.375 C 17.179 385.929,18.229 385.938,199.943 385.938 L 382.699 385.938 384.344 383.846 L 385.989 381.755 385.755 306.307 L 385.522 230.859 383.759 224.609 C 375.298 194.617,354.402 176.774,320.508 170.603 L 318.750 170.283 318.750 137.351 C 318.750 107.891,318.615 104.270,317.465 103.000 C 316.759 102.220,293.739 89.536,266.309 74.814 L 216.437 48.047 216.422 32.617 C 216.401 11.508,223.333 14.063,166.072 14.063 L 118.863 14.063 117.244 16.121 M204.688 35.938 L 204.688 46.094 166.016 46.094 L 127.344 46.094 127.344 35.938 L 127.344 25.781 166.016 25.781 L 204.688 25.781 204.688 35.938 M245.938 77.068 C 266.434 88.088,284.609 97.928,286.328 98.935 L 289.453 100.766 166.016 100.766 L 42.578 100.766 83.203 78.916 L 123.828 57.066 166.250 57.049 L 208.672 57.031 245.938 77.068 M62.500 243.359 L 62.500 374.219 44.141 374.219 L 25.781 374.219 25.781 243.359 L 25.781 112.500 44.141 112.500 L 62.500 112.500 62.500 243.359 M116.406 123.828 L 116.406 135.156 95.313 135.156 L 74.219 135.156 74.219 123.828 L 74.219 112.500 95.313 112.500 L 116.406 112.500 116.406 123.828 M307.813 141.323 C 307.813 172.904,308.094 171.094,303.186 171.094 C 279.697 171.094,251.388 195.700,242.808 223.573 L 241.046 229.297 240.812 302.148 L 240.579 375.000 184.352 375.000 L 128.125 375.000 128.125 243.750 L 128.125 112.500 217.969 112.500 L 307.813 112.500 307.813 141.323 M116.406 157.422 L 116.406 168.750 95.313 168.750 L 74.219 168.750 74.219 157.422 L 74.219 146.094 95.313 146.094 L 116.406 146.094 116.406 157.422 M116.406 191.797 L 116.406 203.125 95.313 203.125 L 74.219 203.125 74.219 191.797 L 74.219 180.469 95.313 180.469 L 116.406 180.469 116.406 191.797 M327.023 183.586 C 350.979 189.613,369.816 209.984,373.808 234.180 L 374.356 237.500 313.350 237.500 L 252.344 237.500 252.344 235.672 C 252.344 229.014,257.593 215.950,263.694 207.422 C 277.988 187.441,303.773 177.736,327.023 183.586 M116.406 226.172 L 116.406 237.500 95.313 237.500 L 74.219 237.500 74.219 226.172 L 74.219 214.844 95.313 214.844 L 116.406 214.844 116.406 226.172 M116.406 260.547 L 116.406 271.875 95.313 271.875 L 74.219 271.875 74.219 260.547 L 74.219 249.219 95.313 249.219 L 116.406 249.219 116.406 260.547 M375.000 311.719 L 375.000 374.219 313.281 374.219 L 251.563 374.219 251.563 311.719 L 251.563 249.219 313.281 249.219 L 375.000 249.219 375.000 311.719 M350.781 277.344 C 349.408 278.717,349.219 279.948,349.219 287.500 C 349.219 297.374,350.132 299.219,355.021 299.219 C 359.691 299.219,360.938 296.645,360.938 287.004 C 360.938 277.642,359.966 275.781,355.078 275.781 C 353.385 275.781,351.749 276.376,350.781 277.344 M97.754 283.594 L 116.406 283.594 116.406 294.922 L 116.406 306.250 95.313 306.250 L 74.219 306.250 74.219 294.434 L 74.219 282.617 76.660 283.105 C 78.003 283.374,87.495 283.594,97.754 283.594 M351.355 309.371 L 349.219 311.051 349.219 332.695 C 349.219 357.424,349.304 357.813,354.732 357.813 C 360.903 357.813,360.938 357.675,360.938 333.290 C 360.938 314.059,360.799 311.725,359.570 310.245 C 357.484 307.733,353.919 307.353,351.355 309.371 M116.406 328.906 L 116.406 340.625 95.313 340.625 L 74.219 340.625 74.219 328.906 L 74.219 317.188 95.313 317.188 L 116.406 317.188 116.406 328.906 M116.406 363.281 L 116.406 375.000 95.313 375.000 L 74.219 375.000 74.219 363.281 L 74.219 351.563 95.313 351.563 L 116.406 351.563 116.406 363.281 " /> </Grid>

回答 1 投票 0

控件模板中的 WPF XAML 菜单绑定

我有一个自定义菜单,其中的 ItemsSource 绑定到我的视图模型中的 ObservableCollection。为了自定义菜单,我在样式中使用 ControlTemplate,并且 ControlTemplate 包含一个实验室...

回答 1 投票 0

有没有办法在WPF文本框中添加复制事件的处理程序?

是否有与文本框控件的 HTML onCopy 事件等效的 WPF?我想在将文本复制到剪贴板之前进行一些处理。

回答 1 投票 0

在WPF中如何获取应用边距后控件的可见大小?

我有一个网格,其宽度设置为250。窗口的宽度为600。网格的左右边距设置为50和400。所以渲染的网格宽度减少为600-(50+ 400)= 150。 我...

回答 1 投票 0

在WPF中画十字

我有一个 WPF 控件。 我需要在背景中有一个十字架,如下所示: 之后,我就可以在“交叉”背景上添加其他控件: 我应该如何画十字,知道当我

回答 6 投票 0

强制 MediaElement 在播放后释放流

我正在创建一个录音机控件,具有播放功能。 我使用媒体元素来播放录制的音频,如下所示: 使用 (var storage = System.IO.IsolatedStorage.IsolatedStorage...

回答 4 投票 0

UserControl 中的 MoveFocus()

我正在使用 UserControl 在 WPF 中构建自定义 DatePicker。我的控件里面有 3 个文本框,负责根据文化信息指示日、月和年。 我正在尝试移动 f...

回答 1 投票 0

WPF XAML 中的 ListView 和 StackPanel 有什么区别?

我遇到了显示多个子元素的问题,使用 ListView 时出现水平问题,使用 StackPanel 时出现垂直问题。也许我应该使用另一个集合

回答 1 投票 0

WPF 触摸屏显示器检测问题

我正在努力使我的 wpf 应用程序触摸启用。我已连接到触摸屏辅助显示器。 我面临一个问题。所有触摸事件都被解释为鼠标(点击)事件...

回答 1 投票 0

当从直接代码之外的其他位置执行操作时,如何更新 XAML 中的值?

我有点进退两难。一段时间以来,我一直在为一个名为 SimHub 的应用程序开发一个插件,该插件在很大程度上可以工作。我正在进入一个我想保持印象的阶段......

回答 1 投票 0

如何在c# wpf中将命令绑定到超链接?

我知道我可以使用以下代码创建 RequestNavigate 事件的处理程序: 私有静态只读 ProcessStartInfo s_previewLinkProcessStartInfo = new() { UseShellExecute = true }; 私人空间

回答 1 投票 0

WPF ListBox.SelectedItems 作为 ListBoxItem

有没有办法在WPF中的SelectionChanged(在ListBox上)事件中将ListBox的选定项作为ListBoxItem? 现在,当我调用 listBox.SelectedItems 时,我会得到项目列表...

回答 2 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.