小编Pea*_*son的帖子

WPF WindowChrome:最大化窗口的边缘不在屏幕上

我使用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包含的值不正确.

c# wpf xaml window-chrome .net-4.5

13
推荐指数
2
解决办法
3091
查看次数

编译器错误:"错误CS0307:变量'int'不能与类型参数一起使用"

如果我有以下代码:

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'是一个变量但是像一个类型一样使用

为什么会出现这些错误?代码有什么问题?

.net c# compiler-errors visual-studio

13
推荐指数
1
解决办法
1003
查看次数

DrawingImage 中的样式绑定错误

<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)

c# data-binding wpf xaml imagesource

5
推荐指数
1
解决办法
1042
查看次数

CheckBox CheckChanged事件

之后Checkbox.IsChecked = true,Checked事件被触发.之后Checkbox.IsChecked = false,UnChecked事件被触发.但之后发生了什么事IsChecked = null

.net c# wpf checkbox events

5
推荐指数
1
解决办法
169
查看次数

什么是ContinueWith默认值

我在官方文档中使用ContinueWith(Action<Task> continuationAction)了什么值CancellationToken,TaskContinuationOptions以及TaskScheduler在哪里可以找到它?

.net c# multithreading task task-parallel-library

4
推荐指数
1
解决办法
681
查看次数

在 WPF 窗口中接收带有窗口消息的键盘事件 (HwndSource.AddHook)

我有一个带有文本框的窗口。光标位于文本框内。如果我按下一个键,那么我会在 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)

c# wpf wndproc keyboard-hook window-messages

0
推荐指数
1
解决办法
2126
查看次数