小编Dom*_*nas的帖子

MarkupExtension 对于 Setter.Value 无效。唯一支持的 MarkupExtension 类型是 DynamicResourceExtension 和 BindingBase 或派生类型

我有一个自定义标记扩展“ThemeExtension”,用于从我的 DefaultTheme.xaml ResourceDictionary 提供“SolidColorBrush”。

调用示例:BorderBrush="{extensions:Theme Key= FooKeyValue}"

它在运行时运行没有任何问题,但有时它在设计时开始崩溃,我无法再开发。设计师崩溃了。重建、清理解决方案、操作系统重新启动不再有帮助。如果我更改 XAML 代码内部的某些值,它正好适用于 1 个绘图!然后它又崩溃了!

预览

预览

XAML 堆栈跟踪

bei System.Windows.Setter.Seal()
bei System.Windows.SetterBaseCollection.Seal()
bei System.Windows.Style.Seal()
bei System.Windows.StyleHelper.UpdateStyleCache(FrameworkElement fe, FrameworkContentElement fce, Style oldStyle, Style newStyle, Style& styleCache)
bei System.Windows.FrameworkElement.OnStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
bei System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
bei System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
bei System.Windows.DependencyObject.InvalidateProperty(DependencyProperty dp, Boolean preserveCurrentValue)
bei System.Windows.FrameworkElement.UpdateStyleProperty()
bei System.Windows.FrameworkElement.OnInitialized(EventArgs e)
bei System.Windows.Controls.Primitives.Selector.OnInitialized(EventArgs e)
bei System.Windows.FrameworkElement.TryFireInitialized()
bei …
Run Code Online (Sandbox Code Playgroud)

c# xaml markup-extensions visual-studio visual-studio-2017

6
推荐指数
1
解决办法
1702
查看次数

带有 List<Dictionary<string, string>> 的 GraphQL.NET 突变 | JSON 字符串

我想alarms在我的服务器应用程序上注册。为了防止传递 10+ 个参数,我alarm在客户端序列化我的并将其传递List<JSONString>给我的服务器。反序列化它,注册它并给出注册的alarm.

现在我的问题是,我不知道如何传递这些参数:

使用 Mutation - DictionaryType

字典

类型为 \"[String]!\" 的变量 \"$params\" 用于期望类型 \"[DictionaryType]!\" 的位置。"

使用 Mutation - StringGraphType

“无法将值转换为 AST:System.Collections.Generic.Dictionary`2[System.String,System.Object]”,**

服务器

变异 - DictionaryType

public class Mutation : ObjectGraphType
{
    public Mutation()
    {
        Name = "Mutation";

        FieldAsync<HtStaticAlarmBaseType>(
            "registerStaticAlarms",
            "Register a list with static alarms.",
            arguments: new QueryArguments(
                new QueryArgument<NonNullGraphType<ListGraphType<DictionaryType>>> {Name = "params"}
            ),
            resolve: async context =>
            {
                List<object> parameterString = context.GetArgument<List<object>>("params");

                //TODO

                return null;
            }
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

变异 - …

c# graphql graphql-dotnet

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

“dotnet test”在 gitlab-runner 管道中找不到 nunit 测试

我有一个带有NUnit测试项目的解决方案(Foo.Test)。

+-- src
|   +-- Foo.Gui
|   +-- Foo.Test
Run Code Online (Sandbox Code Playgroud)
+-- src
|   +-- Foo.Gui
|   +-- Foo.Test
Run Code Online (Sandbox Code Playgroud)

以下调用用于测试:

dotnet test --no-build -c Release -v n src\%TESTPROJECT%\%TESTPROJECT%.csproj --logger "trx;LogFileName=testreport.trx"

如果我在本地运行它,一切都会按预期工作:

在此输入图像描述

对构建服务器的相同调用没有找到任何测试:

在此输入图像描述

gitlab-ci.yml

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="TestResults\**" />
    <EmbeddedResource Remove="TestResults\**" />
    <None Remove="TestResults\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="GitVersionTask" Version="5.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="nunit" Version="3.12.0" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Foo.Gui\Foo.Gui.csproj" …
Run Code Online (Sandbox Code Playgroud)

.net nunit unit-testing gitlab-ci-runner dotnet-test

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

VisualStudio UWP/XAML 设计器未显示 UserControl | 由于缺少程序集,无法显示元素“foo”

我的项目文件夹中有两个项目:

  • HtSuite.UWP | Library
  • HtSuite.UWP.Leitstand | Applicaton

Libraryis an 中UserControl NamePasswordControl,我可以在XAML | Designer.

在此处输入图片说明

当我将NamePasswordControl放在我的LoginView.xaml(也在Library)上时,出现以下错误:

由于缺少程序集,无法显示元素“passwordView”。构建应用程序后,您可能能够查看此控件

在此处输入图片说明

当我运行时Application,一切都按预期工作。

在此处输入图片说明

到目前为止我尝试了以下步骤(没有成功):

  • 清洁溶液
  • 重建项目
  • 删除缓存
  • dotnet clean
  • dotnet restore
  • 重新启动的窗口
  • 更新了 VisualStudio ( v16.6.0) 并尝试了v16.7.0 预览版 1

有人知道如何修复预览吗?


具有相同行为的最小测试项目:

https://files.dominic-jonas.de/stackoverflow/ClassLibrary2.zip

一个类库,其中有一个 UserControl 和一个应在其上显示的页面。但是,错误也显示在那里,无法预览


日志

  • 28.05.2020 Nico Zhu - MSFT可以成功加载TestProject的预览(visual studio 2017 v15.9.17)。我能不能用vs2017显示预览。

c# visual-studio win-universal-app uwp uwp-xaml

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

在WPF中相对于其容器绘制对角线Text/TextBlock/Label/Control

我有一个Grid动态的大小.在里面我想画一个对角线TextBlock.我已经有一个对角线Path,您可以设置LineGeometry动态调整.但我找不到吊坠TextBlock.我错过了什么吗?

<Grid>
    <TextBlock Text="Draft" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="180" FontWeight="Bold" Foreground="#FFA43A3A" RenderTransformOrigin="0.5,0.5"/>
    <Path Grid.Row="2" Grid.Column="0" Stroke="Red" StrokeThickness="2" Stretch="Fill">
        <Path.Data>
            <LineGeometry StartPoint="1,0" EndPoint="0,1" />                
        </Path.Data>            
    </Path>
</Grid>
Run Code Online (Sandbox Code Playgroud)

预习

在此输入图像描述

目标

这是我希望没有设置绝对值RotateTransform.

在此输入图像描述

两种解决方案的比较

red前景FrankM的解决方案,green一个是从亨利克·汉森

https://imgur.com/a/92X0LXI

c# wpf xaml blend expression-blend

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

显示 TextBlock 文本的工具提示(具有自定义样式)

我有以下问题。我有一个带有 DataGridTemplateColumn 的 DataGrid,我想用弹出窗口显示单元格的文本(因为它可以被修剪)。

这是我的 xaml 代码:

                    <DataGridTemplateColumn>
                        <DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock 
                                    Text="{Binding Description}" 
                                    TextTrimming="CharacterEllipsis">
                                    <TextBlock.ToolTip>
                                        <ToolTip Style="{StaticResource ToolTipBrowserDescription}" ToolTip="test"/>
                                    </TextBlock.ToolTip>
                                </TextBlock>
                            </DataTemplate>
                        </DataGridTemplateColumn.CellTemplate>
                    </DataGridTemplateColumn>
Run Code Online (Sandbox Code Playgroud)

风格:

<Style TargetType="{x:Type ToolTip}" x:Key="ToolTipBrowserDescription">
    <Setter Property="DataContext" Value="{Binding RelativeSource={x:Static RelativeSource.Self}}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToolTip}">
                <Border BorderBrush="{StaticResource HT_Background_DarkGrey}" Background="{StaticResource HT_Background_LightGrey3}" BorderThickness="1">
                    <TextBlock Text="{Binding ToolTip}" FontWeight="Bold" TextWrapping="Wrap" Margin="5" MinWidth="50" MaxWidth="{TemplateBinding MaxWidth}"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)

工具提示1

但是,当我将工具提示属性从“test”设置为“{Binding Description}”时,工具提示(如图所示)为空。

有没有人给我解决方案。我被困了大约2小时..

.net c# wpf xaml

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

SQLite:内存:​​使用/处置的数据库使用情况

我已将我的全部包裹SQL Connections在一个using声明中。

\n\n
using (DbConnection dbConnection = GetConnection())\n{\n    using (DbCommand dbCommand = dbConnection.CreateCommand(cmdInsert))\n    {\n        //some work\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

因为UnitTests我应该使用 a :memory: database,但是database关闭连接后会自动删除。

\n\n

https://www.sqlite.org/inmemorydb.html

\n\n
\n

当与数据库的最后一个连接关闭时,数据库将被自动删除并回收内存。

\n
\n\n

有没有解决方案如何使用 a:memory: database和 use using?我不想在没有..的情况下编写完全相同的代码两次using

\n\n

完整示例

\n\n

数据库

\n\n
public abstract class SqliteBase\n{\n    public string ConnectionString;\n\n    protected SqliteBase()\n    {      \n        SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder\n        {\n            DataSource = ":memory:",\n            ForeignKeys = true,\n            DefaultTimeout = 3,\n            DateTimeKind …
Run Code Online (Sandbox Code Playgroud)

c# sqlite

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

从程序集中获取所有资源的列表

我有一个文件夹,Resources想要获取所有paths.

在此处输入图片说明

如果我将它们设置为 an embedded resource,我可以通过

var resources = Assembly.GetExecutingAssembly().GetManifestResourceNames();
Run Code Online (Sandbox Code Playgroud)

当遵循这个答案/sf/answers/135452481/ 时,我不应该再使用embedded resource了,或者我做错了什么?

c# wpf

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

"http://schemas.microsoft.com/expression/blend/2008"命名空间中不存在"DataContext"属性

我在我的DataContext内部使用DesignTime WPF Styles获得全面IntelliSense支持.

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:alarm="clr-namespace:Foo.Alarm;assembly=HtCore"
    mc:Ignorable="d">

    <Style TargetType="TreeViewItem" d:DataContext="{d:DesignInstance alarm:HtAlarmBase}">

    </Style>

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

Designer highlights它并说:

" http://schemas.microsoft.com/expression/blend/2008 "命名空间中不存在"DataContext"属性

错误

是否有隐藏此"错误消息"的解决方案?

wpf resharper xaml

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

RX:如果绑定到 list&lt;string&gt;,则 ComboBox 为空 | ViewModelViewHost 找不到视图模型的有效视图

ViewModel是一个

public List<string> OperationModes { get; } = Enum.GetNames(typeof(EOperationMode)).ToList();
Run Code Online (Sandbox Code Playgroud)

我想绑定到ComboBox.

反应式UI方式| 不工作

this.OneWayBind(ViewModel, model => model.OperationModes, window => window.ComboBoxOperationMode.ItemsSource).DisposeWith(r);
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

如果使用reactiveUI将 绑定listComboBox,我会在console output.

控制台输出

DefaultViewLocator: Failed to resolve view for view model type 'System.Object'.
DefaultViewLocator: Failed to resolve view for view model type 'System.Object'.
ViewModelViewHost: The ViewModelViewHost could not find a valid view for the view model of type System.String and value Passthrough.
Run Code Online (Sandbox Code Playgroud)

xaml 方式 | 在职的

<ComboBox
    x:Name="ComboBoxOperationMode" …
Run Code Online (Sandbox Code Playgroud)

c# data-binding wpf reactiveui

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

从另一个线程更新 ObservableCollection 的最佳/最干净的策略

通常我会检查我是否可以访问ObservableCollection,如果没有,我会调用一个Dispatcher. 这里(上Stackoverflow)还有其他一些解决方案,但我不知道什么是最好和最干净的方法。我认为我的解决方案已经过时,不应再使用。

在我的例子中是ItemsCollection绑定到UI. 该_UpdateTheCollectionFromAnotherThread()会被调用(从另一个thread或将开启另一个thread)并保存数据暂时到items。之后,我会检查访问权限并dispatcher在需要时调用 a 。

这是我必须走的路还是有一些更好更清洁的解决方案?

FooClass

public class FooClass
{
    // ##############################################################################################################################
    // Properties
    // ##############################################################################################################################

    /// <summary>
    /// This Items are bound to my UI.
    /// </summary>
    public ObservableCollection<string> ItemsCollection { get; } = new ObservableCollection<string>();

    // ##############################################################################################################################
    // Singleton pattern
    // ##############################################################################################################################

    /// <summary>
    /// The instance of <see cref="FooClass"/>.
    /// </summary>
    internal static FooClass Instance …
Run Code Online (Sandbox Code Playgroud)

c# wpf multithreading dispatcher observablecollection

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

C# 7.0 独立丢弃混淆 | _ = FooTask() 和 _ = Task.Run(FooTask) 的区别

我有一个Task FooTask应该在后台调用的。中的一个新功能C# 7.0discard函数。正如已经问过的(C# 7.0 独立丢弃混淆),可以通过Task两种方式调用。但是,我还没有能够确切地找出这两个调用有何不同以及它们是否有任何区别。

_ = Task.Run(FooTask);
Run Code Online (Sandbox Code Playgroud)
_ = FooTask();
Run Code Online (Sandbox Code Playgroud)

c# asynchronous c#-7.0

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