BloggerAds廣告

2021年1月29日 星期五

[C#] WPD : How to make a hot key for application

在WPF的程式裡, 想要加入快捷鍵的功能
首先在Resources中建立Command的名稱, 這部份用來連結CommandBindings和InputBindings
<Window.Resources>
	<RoutedUICommand x:Key="OpenFile" Text="Open File"/>
</Window.Resources>
接下來設定CommandBindings
其中CommandBinding_Executed是執行的Function名稱
<Window.CommandBindings>
	<CommandBinding Command="{StaticResource OpenFile}" Executed="CommandBinding_Executed"/>
</Window.CommandBindings>
最後設定InputBindings
<Window.InputBindings>
	<KeyBinding Key="O" Modifiers="Ctrl" Command="{StaticResource OpenFile}"/>
</Window.InputBindings>

2021年1月22日 星期五

[C#] WPF : How to make a button looks like transparent

我試著在WPF的專案上, 讓Button看起來像是Label一樣 設定如下
<Button Name="btnTest" Click="BtnTest_Click" Background="{x:Null}" BorderBrush="{x:Null}">Test</Button>
如果設定成Style, Resource的設定如下
<Window.Resources>
	<Style TargetType="{x:Type Button}" x:Key="TransparentButton">
		<Setter Property="Background" Value="{x:Null}" />
		<Setter Property="BorderBrush" Value="{x:Null}" />
	</Style>
</Window.Resources>
而使用方式為

<Button
Style="{StaticResource TransparentButton}"
Name="btnTest"
Content="Test"
Click="BtnTest_Click"/>