小编Stu*_*urf的帖子

如何在WPF中设置DataGrid标头的样式

DataGrid喜欢这样的:

<DataGrid AutoGenerateColumns="False"  
          Height="221" 
          HorizontalAlignment="Center" 
          VerticalContentAlignment="Center" 
          HorizontalContentAlignment="Center" 
          Margin="6,269,0,0" 
          Name="dataGrid1" 
          VerticalAlignment="Center" 
          Width="875" 
          SelectionChanged="dataGrid1_SelectionChanged">
    <DataGrid.Columns>
        <DataGridTextColumn x:Name="Id" 
                            Header="ID"
                            Binding="{Binding Path=Key}" 
                            HeaderStyle="" />
        <DataGridTemplateColumn Header="Image" 
                                Width="SizeToCells" 
                                IsReadOnly="True" 
                                MinWidth="80">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <Image Width="16" 
                           Height="16"
                           Source="{StaticResource MyImageSource}"
                           HorizontalAlignment="Center" 
                           VerticalAlignment="Center"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)

我怎么能集中DataGrid Header?并适用它的风格?

谢谢


编辑1):

写完这段代码后:

<DataGrid.ColumnHeaderStyle>
    <Style TargetType="{x:Type DataGridColumnHeader}">
        <Setter Property="FontWeight"  Value="Bold" />
        <Setter Property="HorizontalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
    </Style>
</DataGrid.ColumnHeaderStyle>
Run Code Online (Sandbox Code Playgroud)

网格列成为:

在此输入图像描述

为什么?

c# wpf styles c#-4.0

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

如何在控制器中获取数据库上下文

我想了一整天找出获得ApplicationDbContextManageController.cs默认MVC 6项目.

我上网了,谷歌搜索了很多,但似乎没有人像我一样有问题.这可能很简单,但我无法弄清楚.有人有想法吗?

这是我尝试过的:

IServiceProvider service = new IServiceProvider();
var _context = service.GetService<ApplicationDbContext>();
Run Code Online (Sandbox Code Playgroud)

.net c# asp.net-mvc-controller asp.net-core-mvc asp.net-core

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

在两个网络适配器之间创建网桥

我正在尝试使用 Powershell 创建网桥,但没有关于从哪里开始的文档。

是否可以在 Windows 10 计算机上的两个网络适配器之间使用 powershell 创建网桥?

powershell

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

保存文件 - xmlSerializer

我正在创建一个使用此代码序列化文件的方法:

public void Save(Object file, Type type, String path)
{
    // Create a new Serializer
    XmlSerializer serializer = new XmlSerializer(typeof(type));

    // Create a new StreamWriter
    StreamWriter writer = new StreamWriter(@path);

    // Serialize the file
    serializer.Serialize(writer, file);

    // Close the writer
    writer.Close();
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试构建时,Visual Studio告诉我:"错误1找不到类型或命名空间名称'type'(您是否缺少using指令或程序集引用?)c:\ users\erik\documents\visual studio 2013\Projects\FileSerializer\FileSerializer\Class1.cs 16 65 FileSerializer"

为什么是这样?

**编辑*

适用的新代码:

public void Save(Object file, String path, Type type)
{
    // Create a new Serializer
    XmlSerializer serializer = new XmlSerializer(type);

    // Create a new StreamWriter
    TextWriter writer = …
Run Code Online (Sandbox Code Playgroud)

c# xml serialization xml-serialization streamwriter

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

无法从“int”转换为“System.Predicate”

我收到此错误:无法从“int”转换为“System.Predicate ServerHomeWork.Models.Organization”

在 OrgList.Add(Organization.Find(UTO.OrganizationId); 行的一部分,属性 UTO.OrganizationId 是一个 int 但仍然表示出了问题。任何人都可以告诉我这里出了什么问题吗?

代码在这里:

public virtual List<Organisation> Organisation
{
    get
    {
        List<UsersToOrganisations> UserToOrg = UsersToOrganisations.FindListOfOrganisations(UserId);
        List<Organisation> OrgList = new List<Models.Organisation>();

        if (UserToOrg.Count > 0)
            foreach (UsersToOrganisations UTO in UserToOrg)
                OrgList.Add(Organisation.Find(UTO.OrganisationId));
        else
            OrgList.Add(new Organisation("No organisation was found.", 0));


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

这是 UserToOrganization 类

class UsersToOrganisations
{
    public int Id { get; set; }
    public int UserId { get; set; }
    public int OrganisationId { get; set; }
    public bool MainOrganisation { get; set; …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework

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

MongoDB C#驱动程序CancellationToken

有没有人知道CancellationToken的功能,如果您在中添加了一个参数,例如

public static UpdateResult UpdateMany<TDocument>(
    this IMongoCollection<TDocument> collection,
    Expression<Func<TDocument, bool>> filter,
    UpdateDefinition<TDocument> update,
    UpdateOptions options = null,
    CancellationToken cancellationToken = null
)
Run Code Online (Sandbox Code Playgroud)

https://mongodb.github.io/mongo-csharp-driver/2.3/apidocs/html/M_MongoDB_Driver_IMongoCollectionExtensions_UpdateMany__1.htm

是回滚吗?或它是做什么的?

c# cancellation-token mongodb-.net-driver

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

C# gRPC 客户端拦截器设置授权标头

我正在尝试为始终设置配置的 API 令牌的 gRPC 客户端创建一个拦截器。

\n

问题是我找不到设置context.Options.Headers. 如果我正在阅读文档,我需要调用该WithHeaders方法,并且需要设置新的元数据,以便我可以添加更多标头。唯一的问题是仍然没有创建 headers 对象。

\n

有谁知道我做错了什么?

\n

文件:

\n

https://grpc.github.io/grpc/csharp/api/Grpc.Core.CallOptions.html?q=calloptions

\n

代码:

\n
using System;\nusing Floof.Common.Exceptions.IoC;\nusing Grpc.Core;\nusing Grpc.Core.Interceptors;\nusing Microsoft.Extensions.Configuration;\nusing Microsoft.Extensions.Logging;\n\nnamespace Floof.Common.GrpcClient.Interceptors\n{\n    public class AuthorizationHeaderInterceptor : Interceptor\n    {\n        private readonly ILogger<AuthorizationHeaderInterceptor> _logger;\n        public const string Section = "gRPC";\n        public const string Key = "ApiKey";\n\n        private const string AuthorizationHeader = "Authorization";\n        private readonly string _apiToken;\n\n        public AuthorizationHeaderInterceptor(\n            ILogger<AuthorizationHeaderInterceptor> logger,\n            IConfiguration configuration\n        )\n        {\n            if (configuration == null)\n                throw new ArgumentNullException(nameof(configuration));\n            \n            _logger …
Run Code Online (Sandbox Code Playgroud)

c# interceptor grpc

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

由于 SSL 问题,Azure DevOps 部署代理无法连接

由于 SSL 问题,Azure 部署代理几天后不再工作。

我有几台服务器无法再连接到 Azure DevOps。

我发现以下博客应该启用tls 1.2。

https://devblogs.microsoft.com/visualstudio/azure-devops-requires-tls-1-2-on-all-connections-include-visual-studio/

我检查了我们是否启用了正确的安全协议。

C:\azagent\A2> [System.Net.ServicePointManager]::SecurityProtocol
Ssl3, Tls, Tls12
Run Code Online (Sandbox Code Playgroud)

我还按照以下步骤确保在 Windows 寄存器中启用了 TLS。我手动添加了这些值,因为有些值不存在。

Path                                                                                          Name                        Value
----                                                                                          ----                        -----
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319                                 SystemDefaultTlsVersions    1
HKLM:\SOFTWARE\WOW6432Node\Microsoft\.NETFramework\v4.0.30319                                 SchUseStrongCrypto          1
HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319                                             SystemDefaultTlsVersions    1
HKLM:\SOFTWARE\Microsoft\.NETFramework\v4.0.30319                                             SchUseStrongCrypto          1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server    Enabled                     1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Server    DisabledByDefault           0
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client    Enabled                     1
HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client    DisabledByDefault           0
Run Code Online (Sandbox Code Playgroud)

我在下面发布了日志,因为我不知道发生了什么。还有其他人有什么想法吗?

日志:

[2022-02-05 18:38:37Z INFO AgentProcess] Agent package win-x64.
[2022-02-05 18:38:37Z INFO AgentProcess] Running on Windows (X64).
[2022-02-05 18:38:37Z INFO AgentProcess] RuntimeInformation: Microsoft Windows 6.3.9600.
[2022-02-05 …
Run Code Online (Sandbox Code Playgroud)

azure-devops azure-agent

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

使用变量不工作的 sass 减轻函数

我在我的项目中使用 SASS

这里如果我的变量代码

:root, [data-theme="default"] {
    --text-color: #383143;
}
$text-color: var(--text-color);
Run Code Online (Sandbox Code Playgroud)

我正在使用该变量与像波纹管一样的减轻功能,

body {
    color: lighten($text-color, 10%);
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误,

错误:参数$colorlighten($color, $amount)必须对资产/ SCSS /碱/ typography.scss的第10行的彩色,在功能lighten

如何在该变量中使用 lighten 函数?我需要使用--text-color: #383143; 用于颜色切换器目的的格式。

css sass

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

MongoDB c#驱动创建索引

我刚刚将我的MongoDB从2.5.0更新到2.7.0.Visual Studio告诉我,当我想创建这样的索引时:

protected override Task OnPerformMaintenanceAsync(CancellationToken cancellationToken) =>
  NotificationLogs.Indexes.CreateOneAsync(Builders<NotificationLog>.IndexKeys.Ascending(_ => _.TimestampUtc));
Run Code Online (Sandbox Code Playgroud)

已经过时了.他们希望我们使用CreateIndexModel https://mongodb.github.io/mongo-csharp-driver/2.6/apidocs/html/T_MongoDB_Driver_CreateIndexModel_1.htm

唯一的问题是我找不到一个能够实现同样功能的例子.

我试过了:

protected Task OnPerformMaintenanceTestAsync(CancellationToken cancellationToken)
{
  // Old approach
  // var builder = Builders<NotificationLog>.IndexKeys.Ascending(x => x.TimestampUtc);

  // New approach
  var indexModel = new CreateIndexModel<NotificationLog>(nameof(NotificationLog.TimestampUtc));

  return NotificationLogs.Indexes.CreateOneAsync(indexModel);
}
Run Code Online (Sandbox Code Playgroud)

我一直得到以下异常:

System.FormatException: 'JSON reader was expecting a value but found 'TimestampUtc'.'

c# mongodb-.net-driver

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