小编Sha*_*owe的帖子

代码在发布与调试模式下的行为方式不同

在Release模式和debug模式下运行时,我们有一些单元测试失败.如果我在发布模式下附加调试器,则测试通过.有太多的代码要在这里发布,所以我真的只是在寻找调试发布模式问题的最佳实践.我检查过:

  • DEBUG和RELEASE预处理程序指令,但我没有找到任何指令.
  • 条件方法

解决方案:在这种情况下,这是因为我在比较浮点变量是否相等.如果没有重大的重构,我无法将浮点数更改为十进制,所以我添加了一个扩展方法:

public static class FloatExtension
{
    public static bool AlmostEquals(this float f1, float f2, float precision)
    {
        return (Math.Abs(f1 - f2) <= precision);
    }

    public static bool AlmostEquals(this float f1, float f2)
    {
        return AlmostEquals(f1, f2, .00001f);
    }

    public static bool AlmostEquals(this float? f1, float? f2)
    {
        if (f1.HasValue && f2.HasValue)
        {
            return AlmostEquals(f1.Value, f2.Value);
        }
        else if (f1 == null && f2 == null)
        {
            return true;
        }
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

.net c# release

9
推荐指数
2
解决办法
6224
查看次数

使用C#解析HTML链接

是否有一个内置的DLL将给我一个字符串链接列表.我想发送一个包含有效html的字符串,并解析所有链接.我似乎记得在.net或非托管库中内置了一些内容.

我找到了一些看起来很有前景的开源项目,但我认为有一个内置模块.如果不是,我可能不得不使用其中之一.如果没有必要的话,我现在不想要外部依赖.

.net html c#

7
推荐指数
3
解决办法
2万
查看次数

在WPF中显示"等待"屏幕

我正在尝试为长时间运行的操作显示请等待对话框.问题是因为这是单线程,即使我告诉WaitScreen显示它永远不会.有没有办法可以更改该屏幕的可见性并立即显示?我将Cursor调用作为示例包含在内.在我调用this.Cursor之后,光标立即更新.这正是我想要的行为.

private void Button_Click(object sender, RoutedEventArgs e)
{
  this.Cursor = System.Windows.Input.Cursors.Pen;
  WaitScreen.Visibility = Visibility.Visible;

  // Do something long here
  for (Int32 i = 0; i < 100000000; i++)
  {
    String s = i.ToString();
  }

  WaitScreen.Visibility = Visibility.Collapsed;
  this.Cursor = System.Windows.Input.Cursors.Arrow; 
}
Run Code Online (Sandbox Code Playgroud)

WaitScreen只是一个Z-index为99的网格,我隐藏并显示.

更新:我真的不想使用后台工作者,除非我必须这样做.代码中有许多地方会发生这种启动和停止.

.net c# wpf xaml multithreading

7
推荐指数
2
解决办法
2万
查看次数

如何在WPF中创建环绕按钮

要求:

  • 必须支持MinWidth属性
  • 只能在一行或两行显示文本.不能换到3个或更多.
  • 在尊重MinWidth时,应使按钮尽可能小
  • 文本只能在空格上包装
  • 无法指定宽度.按钮应保持水平增长.

这是我希望按钮看起来像(请忽略造型,包装是重要的部分)

在此输入图像描述

我正在寻找有关如何动态文本换行的想法.

wpf layout xaml button

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

WPF 网格 SharedSizeGroup 错误

如果您运行此代码并单击选项卡 2,然后再单击选项卡 1,应用程序会变得疯狂并开始来回弹跳列宽。对于如何解决这个问题,有任何的建议吗?

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow"
    Height="350"
    Width="525">
<Grid IsSharedSizeScope="True">
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto"
                          SharedSizeGroup="Col3" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <TextBlock Text="Label 1"
               Grid.Row="0"
               Grid.Column="0" />

    <TextBox Grid.Column="1"
             Grid.Row="0"
             Text="TextBox 1" />

    <TextBlock Text="Label 2"
               Grid.Row="0"
               Grid.Column="2" />

    <TextBox Grid.Column="3"
             Grid.Row="0"
             Text="TextBox 2" />

    <DockPanel Grid.Row="1"
               Grid.Column="2"
               Grid.ColumnSpan="2">

        <TabControl>
            <TabItem Header="Tab 1">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="Col3" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition …
Run Code Online (Sandbox Code Playgroud)

.net wpf xaml

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

如何在Windows Server 2016的IIS上禁用HTTP / 2

我们遇到了一些似乎受http2影响的问题,我想暂时将其关闭以进行故障排除。我尝试了此问题中概述的注册表项,但对Windows Server 2016没有帮助。

如何在Windows 10的IIS上禁用HTTP / 2

iis windows-server-2016

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

如何在 WPF 中的上下文菜单和常规菜单之间共享菜单定义

我有一个已定义的 MenuItem,我想在一个页面上的两个不同菜单之间共享它。该菜单包含两个菜单之间相同的功能,我不想要它的两个副本。无论如何要在 Page.Resources 中定义一个 MenuItem 并在下面的 ContextMenu XAML 中引用它?

<Page.Resources>
    <MenuItem x:Key="123"/>
</Page.Resources>

<ContextMenu>
    <MenuItem>Something hardcoded</MenuItem>

    <!-- include shared menu here -->

</ContextMenu>
Run Code Online (Sandbox Code Playgroud)

.net wpf xaml

2
推荐指数
1
解决办法
2480
查看次数

标签 统计

.net ×5

wpf ×4

xaml ×4

c# ×3

button ×1

html ×1

iis ×1

layout ×1

multithreading ×1

release ×1

windows-server-2016 ×1