我从一个复选框中编辑了一个模板,然后我在其中添加了一个图像而没有定义它的"Source"属性.
风格:
<Style x:Key="ImageCheckbox" TargetType="{x:Type CheckBox}">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
<Setter Property="Background" Value="{StaticResource CheckBoxFillNormal}"/>
<Setter Property="BorderBrush" Value="{StaticResource CheckBoxStroke}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource EmptyCheckBoxFocusVisual}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<Image x:Name="image" Width="20" Height="20" Stretch="UniformToFill"/>
<ControlTemplate.Triggers>
<Trigger Property="HasContent" Value="true">
<Setter Property="FocusVisualStyle" Value="{StaticResource CheckRadioFocusVisual}"/>
<Setter Property="Padding" Value="4,0,0,0"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
我的问题是如何在这段代码中将"Source"属性(在XAML中)传递给"ImageCheckBox"模板:
<CheckBox Content="" Margin="0,2,0,0" Name="btTogglePalette" Grid.Row="1" Command="Helpers:UICommands.TogglePalette"
IsChecked="{Binding Path=PaletteStatus, Mode=TwoWay}" VerticalAlignment="Center" HorizontalAlignment="Center"
Style="{DynamicResource ImageCheckbox}">
Run Code Online (Sandbox Code Playgroud)
这样图像就会显示传递的参数.
谢谢
我希望能够修改wpf文本框的行为,而无需实现新类.
我想要一个像输入/ Alt + Enter行为的Excel,当用户点击"Enter"时,文本框被验证(movefocus ...),但当他点击"ALT + Enter"时,文本框必须添加一个新行(my textbox支持多行:AcceptsReturn为true).
我已经尝试过(在文本框中的PreviewKeyDown事件): - 在此链接之后构建一个KeyEventArgs和一个TextCompositionEventArgs:如何在C#中以编程方式生成keypress事件? - 我尝试过SendKeys.SendWait("{ENTER}")但它发送了许多新的行命令
有没有办法做到这一点 ?
谢谢
private void m_MeasurementName_PreviewKeyDown(object sender, KeyEventArgs e)
{
var tb = (sender as TextBox);
if (Keyboard.Modifiers == ModifierKeys.Alt && Keyboard.IsKeyDown(Key.Enter))
{
// 1st try
var key = "\n\r";
var routedEvent = Keyboard.KeyDownEvent;
tb.RaiseEvent(new TextCompositionEventArgs(InputManager.Current.PrimaryKeyboardDevice, new TextComposition(InputManager.Current, tb, key)) { RoutedEvent = routedEvent });
// 2nd
var key = Key.Enter;
var routedEvent = TextCompositionManager.TextInputEvent;
tb.RaiseEvent(new KeyEventArgs(Keyboard.PrimaryDevice, PresentationSource.FromVisual(tb), 0, key) { RoutedEvent = routedEvent }); …Run Code Online (Sandbox Code Playgroud) direct3d sdk 10和11之间是否存在很大差异(编码方式......),就像direct3d 9和10之间的"它"一样?
谢谢
是否有可能从一个没有聚焦的形式捕获一个热键(例如.Ctrl+ Space),以便在有人使用这个特定的热键时显示它; 而无需在注册表上注册此热键.在"Launchy"应用程序中可以注意到类似的事件.
谢谢
语言:C#(WPF)//操作系统:Windows