我是WPF的新手,我需要您的帮助来创建一个wpf自定义ListBox,其滚动条比默认宽度宽。
我找到了一种适用于包括ListBox的Window WPF的解决方案:
<Window x:Class="iFixCustomControlsTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:iFixCustomControls;assembly=iFixCustomControls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ListBox HorizontalAlignment="Left" Height="92" Margin="56,88,0,0" VerticalAlignment="Top" Width="357" ScrollViewer.VerticalScrollBarVisibility="Visible"/>
</Grid>
<Window.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Width" Value="100"/>
</Style>
</Window.Resources>
</Window>
Run Code Online (Sandbox Code Playgroud)
这种解决方案不是我最喜欢的解决方案,因为它暗示着在包含“经典”列表框的Window中编写代码。我需要的是一种在Generic.xaml中修改列表框内滚动条的方法(如果我理解的很好):
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:iFixCustomControls">
<Style TargetType="local:iFixCustomListBox" BasedOn="{StaticResource {x:Type ListBox}}">
<!--
Setting scrollbar wider than default
Something like:
<Style TargetType="ScrollBar">
<Setter Property="Width" Value="100"/>
</Style>
-->
</Style>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)
.cs文件是:
public class iFixCustomListBox : ListBox
{
static iFixCustomListBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(iFixCustomListBox), new FrameworkPropertyMetadata(typeof(iFixCustomListBox)));
}
}
Run Code Online (Sandbox Code Playgroud)
这种方法是正确的还是更好的方法应该包含用户控件而不是自定义控件?
我开发了一个 vb.net(Visual Studio 2017,.net framework 4.6.1)应用程序,它应该在系统启动时执行,替换 Windows 10 中的“资源管理器”。为此,我修改了 reg 键:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon
Run Code Online (Sandbox Code Playgroud)
和 Reg 值:
Shell="explorer"
Run Code Online (Sandbox Code Playgroud)
用我的应用程序文件名替换它。
这工作正常,但我还需要以管理员身份运行我的应用程序。我可以在 exe 属性上选中“以管理员身份运行”复选框,或者在我的 VS 项目的 app.manifest 上声明它:
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
Run Code Online (Sandbox Code Playgroud)
这些解决方案阻止 Windows 注册表使用Shell值在启动时运行我的应用程序。
因此,我问您是否有任何方法可以使用Shell注册表值(或其他值)以管理员权限运行应用程序。
非常感谢。戴夫。