我使用WindowChrome来自定义Window.当我最大化窗口时,边缘不在屏幕上.我使用以下代码来解决此问题:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<WindowChrome.WindowChrome>
<WindowChrome CaptionHeight="50" CornerRadius="0" GlassFrameThickness="0" NonClientFrameEdges="None" ResizeBorderThickness="5" UseAeroCaptionButtons="False" />
</WindowChrome.WindowChrome>
<Grid>
<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Setter Property="Margin" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=WindowState}" Value="Maximized">
<Setter Property="Margin" Value="{x:Static SystemParameters.WindowResizeBorderThickness}" />
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Style>
<Border BorderThickness="2" BorderBrush="Blue" Background="Yellow" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
我的问题:如何获得正确的像素数,以便边缘不在屏幕之外.
SystemParameters.WindowResizeBorderThickness包含的值不正确.
如果我有以下代码:
private void Check(bool a, bool b)
{
}
private void Check(int a, int b, int c, bool flag)
{
Check(a < b, a > (flag ? c : b - 10));
}
Run Code Online (Sandbox Code Playgroud)
我在调用时遇到编译时错误Check(int, int):
错误CS0307:变量'int'不能与类型参数一起使用
我也得到这些错误:
错误CS0118:'b'是一个变量但是像类型
错误CS0118 一样使用:'a'是一个变量但是像一个类型一样使用
为什么会出现这些错误?代码有什么问题?
<Window x:Class="Project.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="400">
<Window.Resources>
<Style x:Key="IconStyle" TargetType="{x:Type Image}">
<Setter Property="Source">
<Setter.Value>
<DrawingImage>
<DrawingImage.Drawing>
<GeometryDrawing Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ContentControl}}, Path=Foreground}">
<GeometryDrawing.Geometry>
<PathGeometry Figures="M 0,0 0,10 10,5" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingImage.Drawing>
</DrawingImage>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<ContentControl Foreground="Red">
<Image Style="{StaticResource IconStyle}" />
</ContentControl>
<ContentControl Foreground="Blue">
<Image Style="{StaticResource IconStyle}" />
</ContentControl>
</StackPanel>
</Window>
Run Code Online (Sandbox Code Playgroud)
此示例显示了两个图标。图标具有父 ContentControl 的颜色。它工作正常。
但输出显示绑定错误:
System.Windows.Data 错误:4:无法找到引用“RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ContentControl', AncestorLevel='1''的绑定源。BindingExpression:Path=前景;数据项=空;目标元素是“GeometryDrawing”(HashCode=8154127);目标属性是“画笔”(类型“画笔”)
为什么会出现这个错误?我该如何修复它或者我可以忽略它?
编辑
在这种情况下也会发生错误:
<Window x:Class="Project.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Width="100" Height="400">
<Window.Resources>
<Style x:Key="IconStyle" TargetType="{x:Type ContentControl}">
<Setter Property="Template"> …Run Code Online (Sandbox Code Playgroud) 之后Checkbox.IsChecked = true,Checked事件被触发.之后Checkbox.IsChecked = false,UnChecked事件被触发.但之后发生了什么事IsChecked = null?
我在官方文档中使用ContinueWith(Action<Task> continuationAction)了什么值CancellationToken,TaskContinuationOptions以及TaskScheduler在哪里可以找到它?
我有一个带有文本框的窗口。光标位于文本框内。如果我按下一个键,那么我会在 WndProc 中收到一条消息(对于 KeyUp 和 KeyDown)。但是,如果我在 KeyUp 和 KeyDown 事件中设置 e.Handled = true,那么我不会收到任何关键消息:
public partial class MainWindow : Window
{
public MainWindow()
{
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var textBox = new TextBox();
textBox.KeyDown += TextBox_KeyDown;
textBox.KeyUp += TextBox_KeyUp;
Content = textBox;
(PresentationSource.FromVisual(this) as HwndSource).AddHook(WndProc);
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
e.Handled = true;
}
private void TextBox_KeyUp(object sender, KeyEventArgs e)
{
e.Handled = true;
}
private IntPtr WndProc(IntPtr hwnd, int msg, …Run Code Online (Sandbox Code Playgroud)