gpt4 book ai didi

c# - 在 WPF 中查看有错误的应用程序

转载 作者:行者123 更新时间:2023-11-30 22:53:08 24 4
gpt4 key购买 nike

我有一个应用程序会在屏幕尺寸改变时破坏图像

下面是画面

哪里会出错?什么会导致这种情况?我什至不知道去哪里看,因为它不是永久性错误,一次又一次消失了

这就是我在每个 View 中使用行和数字加载项目的方式:

<ItemsControl ItemsSource="{Binding ConnectorsGridsHorizontal, Mode=TwoWay}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>

功能图1元素:

public Grid DrawConnector1(Thickness margin, int nr, bool rotate, bool rightSide)
{
Grid grid = new Grid();
grid.Margin = margin;

grid.HorizontalAlignment = HorizontalAlignment.Left;
grid.Width = S10;
grid.Height = 128;
grid.VerticalAlignment = System.Windows.VerticalAlignment.Center;

Line line = new Line();
line.X1 = S10HALF;
line.X2 = S10HALF;
line.Y1 = 0;
line.Y2 = 128;
line.StrokeDashArray = new System.Windows.Media.DoubleCollection() { 4, 2, 1, 2 };

line.Stroke = System.Windows.Media.Brushes.Green;
line.StrokeThickness = 4;

grid.Children.Add(line);

Grid inGrid = new Grid();
inGrid.Width = S10;
inGrid.Height = HF;
inGrid.Background = System.Windows.Media.Brushes.Black;

grid.Children.Add(inGrid);

Border br = new Border();
br.BorderThickness = new Thickness(0);
br.CornerRadius = new CornerRadius(10);
br.Background = System.Windows.Media.Brushes.White;
br.Margin = new Thickness(-10, -10, -10, -10);
br.Width = 20;
br.Height = 20;
br.VerticalAlignment = rightSide ? VerticalAlignment.Top : VerticalAlignment.Bottom;
br.RenderSize = new System.Windows.Size(br.ActualWidth + 1, br.ActualHeight + 1);

if (SelectedConnector + 1 == nr) br.Background = System.Windows.Media.Brushes.Green;
else br.Background = System.Windows.Media.Brushes.White;

if (DisableGreenMark) br.Background = System.Windows.Media.Brushes.White;

TextBlock txtBlock = new TextBlock();
txtBlock.FontSize = 16;
txtBlock.Text = nr.ToString();
txtBlock.Foreground = new SolidColorBrush(Colors.Black);
txtBlock.VerticalAlignment = VerticalAlignment.Center;
txtBlock.HorizontalAlignment = HorizontalAlignment.Center;

br.Child = txtBlock;

grid.Children.Add(br);

Binding b = new Binding("S60_20");
b.Mode = BindingMode.Default;
grid.SetBinding(Canvas.TopProperty, b);

return grid;
}

动图:

enter image description here

我也在使用 SnapsToDevicePixels="true"

最佳答案

首先,尝试这样做:

br.HorizontalAlignment = HorizontalAlignment.Stretch;
br.Margin = new Thickness(0, 0, 0, 0);
  • 不要使用负值的 margin
  • Stretch 将为您提供元素扩展

侧切可能是由于元素的 strip 太窄造成的:

你有:

grid.Width = S10;

line.X1 = S10HALF;
line.X2 = S10HALF;

这表明您已将宽度设置为大概 10

这里你设置为20

br.Width = 20;
br.Height = 20;

我还建议在这里更改:

grid.Width = S10 * 2;

line.X1 = S10HALF * 2;
line.X2 = S10HALF * 2;

关于c# - 在 WPF 中查看有错误的应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57588033/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com