小编Rox*_*Pro的帖子

如何在扩展器的右上角添加按钮 - WPF DataGrid

我想知道如何将按钮放在我的扩展器的右侧,这是我的扩展器折叠时的外观图片(无论是否扩展,我都需要按钮)。

在此处输入图片说明

我需要得到这个,所以当用户点击按钮时,我必须获取订单 ID 并执行一些操作! 在此处输入图片说明

这是我的代码:

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="10*" />
    </Grid.ColumnDefinitions>

    <DataGrid IsSynchronizedWithCurrentItem="False" Grid.Column="0" VerticalGridLinesBrush="Transparent"  RowHeaderWidth="0" CanUserAddRows="False" AutoGenerateColumns="False"  x:Name="datagrid1" Margin="10,150,8,50" Background="Transparent" RowBackground="#FF494949"  VerticalContentAlignment="Center" HorizontalContentAlignment="Center" ItemsSource="{Binding}">
        <DataGrid.Resources>
            <Style TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="Background" Value="Black"/>
                <Setter Property="Opacity" Value="0.5"/>
                <Setter Property="Foreground" Value="White"/>
                <Setter Property="HorizontalContentAlignment" Value="Center" />
                <Setter Property="FontSize" Value="15"/>
                <Setter Property="FontFamily" Value="Arial"/>
                <Setter Property="Height" Value="50"/>
            </Style>


    <Style x:Key="TextInCellCenter" TargetType="{x:Type TextBlock}" >
        <Setter Property="TextAlignment" Value="Center"/>
    </Style>

    <Style TargetType="{x:Type TextBlock}" x:Key="RightAligElementStyle">
        <Setter Property="TextAlignment" Value="Right"/>
    </Style>

    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#83D744"/>

    </DataGrid.Resources>

        <DataGrid.Columns>
            <DataGridTextColumn Binding="{Binding Title}"       Header="Product Name" …
Run Code Online (Sandbox Code Playgroud)

forms wpf datagrid window expander

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

document.write() 应该在我的页面加载后删除所有现有的 html 吗?

我红色这个:

write() 方法主要用于测试:如果在 HTML 文档完全加载后使用它,它将删除所有现有的 HTML。

所以我决定测试一下,我写了这段代码:

<!doctype html> 
<html>
<head>
 <meta charset="utf-8">
</head>
    <body>
    <p>I'm TEST which should be a deleted?</p>
        <script>
            var drink = "Red bull";
            var lyrics = "";
            var cans = 99;

            while(cans > 0)
            {
                lyrics += cans + " cans of " + drink + " on the wall <br>";   
                cans--;  
            }
            document.write(lyrics);
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我添加了<p>I'm TEST which should be a deleted?</p> 之后我document.write在我的script标签之间调用,这应该删除所有现有的html,包括这一段?

但接下来的输出是:

在此输入图像描述

但段落还在,是不是应该按照这句话删除:

如果在 HTML 文档完全加载后使用它,它将删除所有现有的 …

html javascript dom

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

如何正确使用 C# 8.0 switch case

我已经尝试实现 c# 8.0 switch-case 但不幸的是它没有工作,我想如果 case 满足,则在 switch 表达式中为满足的 case 返回一个特定的字符串。

这是我的代码:

public static void GetErrMsg(Exception ex) =>
   ex switch
   {
       ex is UserNotFoundException => "User is not found.",
       ex is NotAuthorizedException => "You'r not authorized."
   };
Run Code Online (Sandbox Code Playgroud)

但是我收到了以下消息:

错误 CS0201 只能将赋值、调用、递增、递减、等待和新对象表达式用作语句。

错误 CS0029 无法将类型“bool”隐式转换为“System.Exception”

c# error-handling exception switch-statement c#-8.0

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

“已经有一个与此命令关联的打开的 DataReader,必须先关闭它。”

我正在开发需要连接到另一个数据库以获取一些数据的应用程序,为此,我决定使用 SqlConnection、阅读器等。

而且我需要执行一些查询,例如首先我需要为某个用户获取 CARD ID,然后我需要通过该 CARD ID 获取一些数据..

这是我的代码:

#region Connection to another Database

SqlConnection sqlConnection1 = new SqlConnection("Data Source=ComputerOne; Initial Catalog=TestDatabase;Integrated Security=False; User ID=test; Password=test123;");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "Select * From Users Where CardID=" + "'" + user.CardID + "'";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();

string cardID = "";
string quantity="";

while (reader.Read())
{
    cardID = reader["CardID"].ToString();
}
//HOW COULD I WRITE ANOTHER QUERY NOW, FOR EXAMPLE, OK …
Run Code Online (Sandbox Code Playgroud)

c# sql database connection reader

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

How to add value to list when using object initializer?

private PostDto MapIntegration(IntDto integ)
{
    return new PostDto
    {
        prop1 = "7",
        prop2 = "10",
        prop3 = true,
        prop4 = "EA Test",
        product_list.Add(integ) // ERROR This says the name product_list does not exist in current context
    };
}
Run Code Online (Sandbox Code Playgroud)

And when we look at PostDto

public class PostDto 
{
    public string prop1 { get; set; }
    public string prop2 { get; set; }
    public bool prop3 { get; set; }
    public string prop4 { get; set; }
    public List<IntDto> product_list { …
Run Code Online (Sandbox Code Playgroud)

c# object generic-collections .net-core

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

如何将文件发送到列表 - .net core web api - postman

我正在尝试将 afile从 a发送postman到 a web api,方法web api需要一个包含文档类型、文件和文件夹名称的类型列表。发布如下:

网页api方法:

[HttpPost("post-images")]
public async Task<IList<RepositoryItem>> PostAnImages (IList<PostRepoRequest> request)
{
    // rest of the code 
}
Run Code Online (Sandbox Code Playgroud)

PostRepoRequest 类:

public class PostRepoRequest
{
    public FileType FileType { get; set; }
    public IFormFile File { get; set; }
    public string Folder { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

因为可以注意到我从未收到过文件,它总是 null,我也尝试过将标头内容类型设置为multipart/form-data,但效果不佳。

这里可能有什么技巧?

谢谢

干杯

c# multipartform-data asp.net-web-api asp.net-core iformfile

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

在 WPF C# 中实现登录表单

我正在尝试在我的应用程序中创建登录窗口,我对 WPF 还很陌生,这对我来说不太顺利。

这就是我所做的,我什至不确定这是正确的方法,但无论如何我的问题是在代码注释中描述的。

 /// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        Window_LogInScreen loginScreen = new Window_LogInScreen();
        loginScreen.ShowDialog();

        if (loginScreen.DialogResult == true)
        {
            MessageBox.Show("login success I should keep executing my application.."); // how could I continue my application if this condition is allright?
        }
        else
        {
            MessageBox.Show("login failed"); //how could I stop my application if I reach this code, and how to stay on LogIn_Screen form so user …
Run Code Online (Sandbox Code Playgroud)

c# authentication wpf

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

LINQ 表达式无法翻译 - C#

我写了一个简单的查询(问题是当我尝试在Address下面设置时ProductCode):

 var query = _connectDBContext.Products
                            .Join(_context.CustomerRelations,
                                Product => Product.ForeignKeyId,
                                CustomerRelation => CustomerRelation.CompanyId,
                                (Product, CustomerRelation) => new { Product, CustomerRelation })
                            .Select(x => new ProductDto
                            {
                                Title = x.Product.Title,
                                ProductCode = x.Product.Code,
                                Address = Map(x.Product.Addresses.OrderBy(x=> x.CreatedDate).FirstOrDefault()),
                                //Address = new AddressDTO // THIS WORKS BUT LOOKS UGLY :(
                                //{
                                //    Address = x.Product.Addresses.OrderBy(x => x.CreatedDate).FirstOrDefault().Address,
                                //    Country = x.Product.Addresses.OrderBy(x => x.CreatedDate).FirstOrDefault().Country,
                                //    Zip = x.Product.Addresses.OrderBy(x => x.CreatedDate).FirstOrDefault().Zip,
                                //},
                               
                            })
                            .Where(x => x.Id == x.CustomerRelationId);

           // Rest of the …
Run Code Online (Sandbox Code Playgroud)

c# linq entity-framework entity-framework-6

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

如何避免太多!=空检查

在我的应用程序中,我已经看到太多不等于null的检查,如下所示:

if (receivedRequest != null && receivedRequest.Status != null)
Run Code Online (Sandbox Code Playgroud)

有没有更干净的方式来写这样的东西?

c#

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