wpf 相关问题

Windows Presentation Foundation或WPF是用于在基于Windows的应用程序中呈现用户界面的子系统。

如何在 C# WPF 中在模糊窗口内制作窗口?

这意味着在程序内部在程序的主要内容之上创建了一个模糊,并在其上方创建了一个具有完全不同内容的窗口。 像这儿: 这个概念的例子......

回答 1 投票 0

在 WPF C# 应用程序中创建自定义弹出消息

如何在WPF C#应用程序中创建自定义弹出窗口(消息框),如Windows 8/Windows Store应用程序弹出窗口,创建它是否可行?我需要设计如附图所示 我正在使用

回答 4 投票 0

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

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

回答 1 投票 0

将我的应用程序的整个样式从自定义样式切换为默认的materialDesignStyles

我正在寻找将整个 wpf 应用程序样式从我的自定义样式交换为默认的 MaterialDesign 样式以及在运行时(如果可能)的方法。非常需要帮助。谢谢 我试过了,但不是

wpf
回答 1 投票 0

DisplayMonitor 到 Forms.Screen 映射

我想向用户显示一个下拉列表,其中除了每个条目之外还显示设备名称(如 Windows 分辨率设置)。我可以通过 Windows.Devices.Display.DisplayMonitor 和 rel...

回答 1 投票 0

获取已安装程序的进程名称

如何获取Windows(10)中已安装程序对应的进程名?现在,我正在使用这个: string uninstallKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall&q...

回答 3 投票 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

XAML 边框 dropdownshadow 未按预期工作

我尝试为我的顶部栏创建下拉阴影效果,但它没有按我想要的方式工作。 问题是当我将主视图背景更改为不同颜色时,下拉阴影效果......

回答 1 投票 0

有关 WPF LiveCharts HeatSeries 的一些格式问题

我使用 LiveCharts 的 HeatSeries 控件在我的 WPF 应用程序中创建气候图表(使用 MVVM / Caliburn.Micro)。该图表填充在我的 ViewModel 中,它按预期工作,但我...

回答 1 投票 0

在 WPF XAML 中禁用样式?

有没有办法以编程方式关闭样式? 例如,我有一个链接到所有文本框的样式 我想添加一些代码到 ac...</desc> <question vote="33"> <p>有没有办法以编程方式关闭样式?</p> <p>举个例子,我有一个链接到所有文本框的样式</p> <pre><code>&lt;Style TargetType=&#34;{x:Type TextBox}&#34;&gt; </code></pre> <p>我想添加一些代码来实际停止使用样式元素,因此基本上恢复到默认的控件样式。</p> <p>我需要一种方法来切换我的样式,这样我就可以通过 C# 代码在 Windows 默认样式和我的自定义样式之间切换。</p> <p>有办法做到这一点吗?</p> <p>谢谢</p> <p><strong>工作解决方案</strong></p> <p><a href="http://sa.ndeep.me/post/switching-between-themes-in-wpf" rel="noreferrer">在 WPF 中切换主题</a></p> </question> <answer tick="true" vote="79"> <p>要将样式设置为默认,</p> <p>在 XAML 使用中,</p> <pre><code>&lt;TextBox Style=&#34;{x:Null}&#34; /&gt; </code></pre> <p>在C#中使用,</p> <pre><code>myTextBox.Style = null; </code></pre> <hr/> <p>如果多个资源的样式需要设置为null,请参阅<strong>CodeNaked的</strong>响应。</p> <hr/> <p>在代码背后,我认为这就是您想要实现的目标:</p> <pre><code>Style myStyle = (Style)Application.Current.Resources[&#34;myStyleName&#34;]; public void SetDefaultStyle() { if(Application.Current.Resources.Contains(typeof(TextBox))) Application.Current.Resources.Remove(typeof(TextBox)); Application.Current.Resources.Add(typeof(TextBox), new Style() { TargetType = typeof(TextBox) }); } public void SetCustomStyle() { if (Application.Current.Resources.Contains(typeof(TextBox))) Application.Current.Resources.Remove(typeof(TextBox)); Application.Current.Resources.Add(typeof(TextBox), myStyle); } </code></pre> </answer> <answer tick="false" vote="23"> <p>您可以注入一个空白样式,该样式优先于其他样式。像这样:</p> <pre><code>&lt;Window&gt; &lt;Window.Resources&gt; &lt;Style TargetType=&#34;TextBox&#34;&gt; &lt;Setter Property=&#34;Background&#34; Value=&#34;Red&#34; /&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;Grid.Resources&gt; &lt;Style TargetType=&#34;TextBox&#34; /&gt; &lt;/Grid.Resources&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>在上面的示例中,只有网格的隐式样式会应用于网格中的文本框。您甚至可以通过编程方式将其添加到网格中,例如:</p> <pre><code>this.grid.Resources.Add(typeof(TextBox), new Style() { TargetType = typeof(TextBox) }); </code></pre> </answer> <answer tick="false" vote="3"> <p>我知道答案已被接受,但我想添加我的解决方案,该解决方案在以下情况下效果很好:</p> <ul> <li>使用 mahapps.metro 的一个主要应用程序</li> <li>从主应用程序导入的附加项目没有引用 mahapps.metro,它作为插件导入(动态加载编译的 .dll)</li> <li>使用 < ToolBar> 将所有内容重新设置为 null,因此 mahapps.metro 样式不会应用于工具栏中的项目。</li> <li>usercontrol 用于为主应用程序提供自定义控件。</li> </ul> <p>在用户控制根目录中设置资源:</p> <pre><code>&lt;UserControl.Resources&gt; &lt;Style x:Key=&#34;ButtonStyle&#34; TargetType=&#34;Button&#34; BasedOn=&#34;{StaticResource {x:Type Button}}&#34; /&gt; &lt;Style x:Key=&#34;ComboBoxStyle&#34; TargetType=&#34;ComboBox&#34; BasedOn=&#34;{StaticResource {x:Type ComboBox}}&#34; /&gt; &lt;/UserControl.Resources&gt; </code></pre> <p>那么工具栏代码可以如下</p> <pre><code> &lt;ToolBar&gt; Block Template: &lt;ComboBox Style=&#34;{StaticResource ComboBoxStyle}&#34;/&gt; &lt;Button Content=&#34;Generate!&#34; Style=&#34;{StaticResource ButtonStyle}&#34;/&gt; &lt;/ToolBar&gt; </code></pre> <p>这成功地将主应用程序样式应用到 < ToolBar></p> 内的控件 </answer> <answer tick="false" vote="1"> <p>在 Xaml 中,您可以通过显式设置样式来覆盖它。在代码隐藏中,您还可以显式设置样式。</p> <pre><code>&lt;TextBox Style=&#34;{StaticResource SomeOtherStyle}&#34;/&gt; myTextBox.Style = Application.Resources[&#34;SomeOtherStyle&#34;]; </code></pre> </answer> </body></html>

回答 0 投票 0

C# Wpf:如何设置菜单项中项目的背景颜色

我想设置菜单项中菜单项的背景颜色这个 我的上下文菜单有一个样式,但它显然不会改变它的颜色 我尝试过更改菜单项

回答 1 投票 0

菜单项样式

我有一个包含以下项目的上下文菜单 我有一个包含以下项目的上下文菜单 <ContextMenu x:Name="NotificoContextMenu" x:Shared="false" x:Key="SysTrayMenu" x:FieldModifier="public" Loaded="NotificoContextMenu_Loaded" Style="{DynamicResource conte}"> <MenuItem Header="Connect" x:Name="ConnectMenuItem" x:FieldModifier="public" /> <MenuItem Header="Ping" Command="{Binding PingCommand}"/> <MenuItem Header="Show Window" Command="{Binding ShowWindowCommand}" /> <Separator /> <MenuItem Header="Exit" Command="{Binding ExitApplicationCommand}" /> </ContextMenu> 对于 ConnectMenuItem,我从代码中添加菜单项 我有一个上下文菜单样式,它适用于所有菜单项,除了我从代码中添加的菜单项,我应该做什么 这是我的上下文菜单的样式 <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type ContextMenu}" x:Key="conte"> <Setter Property="Background" Value="{DynamicResource PrimaryDark}" /> <Setter Property="Foreground" Value="{DynamicResource Secendery}" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="HasDropShadow" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContextMenu}"> <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="0.5" CornerRadius="5"> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle" /> </Border> <ControlTemplate.Triggers> <Trigger Property="HasDropShadow" Value="true"> <Setter TargetName="Border" Property="Padding" Value="0,3,0,3" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> 日夜寻找时发现了一些灵魂出处 这是完整的 Windows 资源文件: <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type ContextMenu}" x:Key="conte"> <Setter Property="Background" Value="{DynamicResource PrimaryDark}" /> <Setter Property="Foreground" Value="{DynamicResource Secendery}" /> <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="HasDropShadow" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ContextMenu}"> <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Foreground}" BorderThickness="0.85" CornerRadius="5"> <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"> </StackPanel> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> <Style TargetType="{x:Type MenuItem}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type MenuItem}"> <Grid SnapsToDevicePixels="true"> <DockPanel> <ContentPresenter x:Name="Icon" ContentSource="Icon" Margin="4,0,6,0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="Center"/> <Path x:Name="GlyphPanel" Fill="{TemplateBinding Foreground}" FlowDirection="LeftToRight" Margin="10,0,0,0" Visibility="Collapsed" VerticalAlignment="Center"/> <ContentPresenter x:Name="content" ContentSource="Header" Margin="10,3" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </DockPanel> <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="false" HorizontalOffset="0" IsOpen="{Binding IsSubmenuOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.MenuPopupAnimationKey}}" Placement="Left" VerticalOffset="0"> <Border BorderThickness="0.85" CornerRadius="2" BorderBrush="{DynamicResource Secendery}" Background="{TemplateBinding Background}"> <ScrollViewer x:Name="SubMenuScrollViewer" CanContentScroll="true" Style="{DynamicResource {ComponentResourceKey ResourceId=MenuScrollViewer, TypeInTargetAssembly={x:Type FrameworkElement}}}"> <Grid RenderOptions.ClearTypeHint="Enabled"> <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Cycle" Grid.IsSharedSizeScope="true" Margin="0" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" KeyboardNavigation.TabNavigation="Cycle"/> </Grid> </ScrollViewer> </Border> </Popup> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsMouseOver" Value="True"> <Setter Property="TextBlock.Foreground" Value="White" TargetName="content"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>

回答 1 投票 0

注销并返回 Prism 应用程序中的登录屏幕

我有一个登录序列在基于 prism 的 WPF 应用程序中工作,该应用程序在显示主窗口之前显示登录屏幕。在我的 Bootstrapper 类中,InitializeShell 方法如下所示 ...

回答 2 投票 0

OpenGL上方的透明窗口

我的应用程序在 WPF 托管窗口中具有 OpenGL 引擎。 我创建了半透明的小部件(作为 Window 对象),它应该在 OpenGL 窗口上方显示内容。有时在处理申请时...

回答 2 投票 0

WPF TextBox 不切换到新行

我有一个文本框,我希望它是多行的并自动调整大小以适应父级: 我有一个 TextBox,我希望它是多行的并自动调整父级的大小: <TextBox Grid.Row="0" Grid.Column="0" AcceptsReturn="True" HorizontalAlignment="Stretch" IsEnabled="{Binding CanModify}" Margin="0" TextWrapping="Wrap" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged}" VerticalScrollBarVisibility="Auto" VerticalAlignment="Stretch" /> 让 TextBlock 自动切换到新行的大多数建议都是在其属性中添加 TextWrapping="Wrap" ,以防止其拉伸,通常是 AcceptsReturn="True"、VerticalScrollBarVisibility="Auto" 或手动设置 width。正如你所看到的,我唯一还没有尝试过的是宽度,但在我的例子中 TextBox 应该适合容器,其宽度未知(也取决于它的父级)。按照列表中的方式设置属性并没有帮助:插入符号永远不会移动到新行并拉伸 TextBox 和整个窗口。 我该怎么做才能防止 TextBox 拉伸并自动将文本移动到新行? 编辑:容器是一个TabControl。包含选项卡: <TabItem Header="{some binding}"> <Grid> <Grid.RowDefinitions> <RowDefinition SharedSizeGroup="TabHeight" /> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition SharedSizeGroup="TabWidth" /> </Grid.ColumnDefinitions> <TextBox Grid.Row="0" Grid.Column="0" AcceptsReturn="True" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsEnabled="{Binding CanModify}" Margin="0" Style="{some style}" TextWrapping="Wrap" Text="{Binding Comment, UpdateSourceTrigger=PropertyChanged}" VerticalScrollBarVisibility="Auto" /> </Grid> </TabItem> 这个TabControl在于一个简单的Grid,没有任何特定风格的约束。唉,我无法分享应用于 TabControl 的完整样式代码,但我非常感谢任何尝试的想法。 您看到的SharedSizeGroups旨在将整个TabControl拉伸到最宽的选项卡,防止其在选项卡开关上调整大小并仅与另一个选项卡共享(此TabControl中有两个选项卡)。 去掉UpdateSourceTrigger=PropertyChanged,多行就可以了。我不知道为什么,但这对我来说就是问题。

回答 1 投票 0

从聚焦的 TabItem 中删除边框底部

单击选项卡后,我想删除底部的边框。 目前我有这个: 现在我想删除标记的边框部分。 我搜索了很多,发现了这个: 选项卡项目和选项卡控件

回答 1 投票 0

如何在代码隐藏中使用WPF的星号大小值?

我在代码隐藏中创建了一些控件,并希望动态设置其大小。 我可以分配数值以及 System.Windows.GridLength.Auto,但没有相当于“*”的值。 那是...

回答 1 投票 0

MVVM 导航 | View 内的按钮

堆栈溢出社区您好, 我是 MVVM 的新手,并且已经编写了一些教程来了解一些基础知识(绑定、RelayCommand 等)。 到目前为止,单个窗口应用程序可以工作...

回答 1 投票 0

BitmapCache 导致 WPF 应用程序锁定

场景如下: 1:我们的WPF应用程序启动 2:WPF 应用程序加载各种用户控件,包括一些使用 WPF 4 中新的 BitmapCache 功能的控件 3:点击 ctrl-alt-delete 或 win+...

回答 3 投票 0

WPF 应用程序命令行参数而不是启动 GUI

我有 WPF 应用程序,我想添加在命令行上执行操作的选项,而不是打开 GUI。 有没有办法在我的应用程序中获取命令行参数,以防......

回答 2 投票 0

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