小编Sea*_*and的帖子

WPF 中的 UseLayoutRounding 和高 DPI

我们的 WPF 应用程序使用 .NET 4.5,默认情况下在每个窗口的根级别启用 UseLayoutRounding。在 Windows 7 和 Windows 8 上,我们的应用程序在 100% 和 125% DPI 设置下看起来不错。然而,一旦我们将其提高到 150%,我们就会开始在整个产品中出现双粗边框线的问题。如果我们将 UseLayoutRounding 设置为 150%,那么控件和边框会突然看起来好多了。我们正在研究根据 DPI 动态设置此设置。

我想了解的是显示器的物理 DPI 如何发挥作用。我能期望 DPI 高于正常水平的 1080p 显示器不会出现这种问题吗?如果我在 Surface Pro(不幸的是我们没有)上运行我的应用程序并开启 200% DPI 缩放,我会看到同样的问题吗?

我想让我感到困惑的是,当以 100% 和 125% 排列相邻边框和形状时,UseLayoutRounding 正是我们想要它做的事情,但在 150% 时正好相反。有没有人在这里有任何见解?

wpf dpi

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

WPF:自定义控件属性已被另一个自定义控件错误注册

我创建了两个完全相同的自定义控件,只是它们属于两种不同的类型。

控制一

public class ControlOne : TextEdit
    {
        public static readonly DependencyProperty AwesomeSauceProperty =
         DependencyProperty.Register("AwesomeSauce", typeof(string), typeof(FormTextEditInput));           

        public string AwesomeSauce
        {
            get { return GetValue(AwesomeSauceProperty) as string; }
            set { SetValue(AwesomeSauceProperty, value); }
        }

    }
Run Code Online (Sandbox Code Playgroud)

控制二

public class ControlTwo : PasswordEdit
        {
            public static readonly DependencyProperty AwesomeSauceProperty =
             DependencyProperty.Register("AwesomeSauce", typeof(string), typeof(FormTextEditInput));           

            public string AwesomeSauce
            {
                get { return GetValue(AwesomeSauceProperty) as string; }
                set { SetValue(AwesomeSauceProperty, value); }
            }

        }
Run Code Online (Sandbox Code Playgroud)

在 XAML 中,我只是这样做

<controls:ControlOne AwesomeSauce="Yummy"/>
<controls:ControlTwo AwesomeSauce="Tummy"/>
Run Code Online (Sandbox Code Playgroud)

我得到错误

System.ArgumentException
'AwesomeSauce' property …
Run Code Online (Sandbox Code Playgroud)

wpf xaml wpf-controls

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

为什么鼠标移动时MouseMove事件会触发

我有一个ItemsControl,其ItemsPresenter响应MouseMove事件.项目在数据源中移动,如果移动项目时鼠标位于控件上,则MouseMove即使鼠标未移动,也会导致事件触发.

以下是演示该问题的示例.

XAML:

<ItemsControl Name="ladder" ItemsSource="{Binding Rows}">
    <ItemsControl.Template>
        <ControlTemplate>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <TextBlock Text="Header" Grid.Column="0" />
                <ItemsPresenter Grid.Row="1" 
                                MouseMove="OnMouseMove"/>
            </Grid>                 
        </ControlTemplate>
    </ItemsControl.Template>
</ItemsControl>
Run Code Online (Sandbox Code Playgroud)

C#:

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        Rows.Add(new Row { Name = "0" });
        Rows.Add(new Row { Name = "1" });
        Rows.Add(new Row { Name = "2" });
        Rows.Add(new Row { Name = "3" });
        Rows.Add(new …
Run Code Online (Sandbox Code Playgroud)

c# wpf mousemove

3
推荐指数
1
解决办法
1784
查看次数

XAML前端的内联c#:为什么这不适用于XAML?

场景:使用c#发往Windows 8.1/10(商店应用程序)的桌面,在UWP中开发"胖"客户端.

在我的用户界面中,我尝试使用以下内联

    <StackPanel Grid.Column="0">
    <TextBlock  x:Name="Qty_Size_Crust" Margin="25,10,20,0" Padding="0,0,0,0" TextAlignment="Left" TextWrapping="Wrap" MaxHeight="25" Foreground="#ff230909" FontFamily="Segoe UI" FontSize="16" xml:space="preserve" HorizontalAlignment="Left">
if ({Binding WidgetName} == "Backend")
{             
        <Run Text="{Binding ItemCode, Converter=ItemCodeToDescriptionConverter}"/> 
}
else
{
       <Run Text="See Administrator}"/> 
}
    </TextBlock>
Run Code Online (Sandbox Code Playgroud)

编译器会接受这个,但在执行期间,我既看不到项目描述也看不到管理员.为了完成这项工作,还有什么我应该做的吗?我能够通过将代码放在ViewModel中来解决这个问题,但是想知道为什么这不起作用(或者可能不应该).

c# winrt-xaml win-universal-app windows-8.1-universal

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

如何处理 DependencyProperty 溢出情况?

我有一个UserControl和一个DependencyProperty名为 Value的 int 。这绑定到UserControl.

public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(int), typeof(QuantityUpDown), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnValueChanged, CoerceValue));

public int Value
{
    get { return (int) GetValue(ValueProperty); }
    set { SetValue(ValueProperty, value); }
}

private static object CoerceValue(DependencyObject d, object basevalue)
{
    //Verifies value is not outside Minimum or Maximum
    QuantityUpDown upDown       = d as QuantityUpDown;
    if (upDown == null)
        return basevalue;

    if ((int)basevalue <= 0 && upDown.Instrument != null)
        return upDown.Minimum;

    //Stocks and …
Run Code Online (Sandbox Code Playgroud)

c# wpf

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