小编Sal*_*ari的帖子

使用DoubleAnimation设置图像不透明度

这应该是相当简单的,但我似乎无法做到正确.我有一个集合System.Windows.Controls.Image.当我选择其中一个时,我希望所有其他人都能获得不透明度0.5.我正在使用MVVM,这背后的逻辑(找到所选图像并将其设置为Enabled)已完成ViewModel,并且正在运行.所以基本上这是有效的:

<Image Grid.Row="0" Source="{Binding ItemImage}" IsEnabled="{Binding ItemImageEnabled}">
<Image.Style>
    <Style TargetType="Image">
        <Style.Triggers>
            <Trigger Property="IsEnabled"  Value="False">
                <Setter Property="Opacity" Value="0.5"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Setter Property="Opacity" Value="1.0"/>
            </Trigger>
        </Style.Triggers>
    </Style>
</Image.Style>
</Image>
Run Code Online (Sandbox Code Playgroud)

现在我想的不透明度转变到进行动画,从衰落它1.00.5当没有选择图像,和从衰落0.51.0当它.我会想到这会工作:

<Image Grid.Row="0" Source="{Binding ItemImage}" IsEnabled="{Binding ItemImageEnabled}">
<Image.Style>
    <Style TargetType="Image">
        <Style.Triggers>
            <Trigger Property="IsEnabled"  Value="False">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" From="1" To="0.5" BeginTime="0:0:0" Duration="0:0:1"/>
                        </Storyboard>
                    </BeginStoryboard>
                </Trigger.EnterActions>
            </Trigger>
            <Trigger Property="IsEnabled" Value="True">
                <Trigger.EnterActions>
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation Storyboard.TargetProperty="Opacity" …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml mvvm doubleanimation

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

如何获得元素的父元素?

MainPage.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Grid x:Name="GridA">
        <Grid x:Name="GridB"/>
    </Grid>
</Grid>
Run Code Online (Sandbox Code Playgroud)

有可能从中得到GridB父母GridB

这就是我想要做的

//Null
Panel parent1 = GridB.Parent as Panel;

//Null
Panel parent2 = VisualTreeHelper.GetParent(GridB) as Panel;
Run Code Online (Sandbox Code Playgroud)

所有这些都返回null.

任何的想法?

c# xaml win-universal-app

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

查找文本中“ x”的确切单词的实例数

我正在c#中查找确切的单词“ x”的实例数。例如:

List<string> words = new List<string> {"Mode", "Model", "Model:"};
Text= "This is Model: x Type: y aa: e";
Run Code Online (Sandbox Code Playgroud)

我用过正则表达式:

for(i=0; i<words.count; i++)
{
    word= list[i]
    int count= Regex.Matches(Text,word) 
}
Run Code Online (Sandbox Code Playgroud)

但是它不起作用。以上代码的结果给了count=1每一个ModeModelModel:。我想有我统计是0Mode0Model,但1对于Model:它找到确切的词的实例的数量。

忘了我不能在我的情况下使用split。有什么办法可以让我不使用split吗?

c# regex string

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

实体框架将本地数据添加到数据库列表中

我是Entity Framework的新手,我使用这个方法来查询我的数据库:

var _context = new StudioEntities();
var results = _context.tblStudios.Select(u => new
{
    u.Standort,
    u.Name,
    u.Id
}).ToList();
Run Code Online (Sandbox Code Playgroud)

现在我的目标是添加本地数据,这些数据在数据库中不存在.我尝试使用此代码,但它不起作用:

results.Add(new tblStudio { Id = 0, Name = "Gesamt" });
Run Code Online (Sandbox Code Playgroud)

有人可以帮我弄这个吗?谢谢

编辑:

我的表类看起来像这样:

public partial class tblStudio
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Standort { get; set; }
    public Nullable<int> Plz { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

c# sql linq entity-framework

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

如何检查DataGridView中的所有行是否都不为空?

我有这个问题很长一段时间.

我打算做的是,如果所有的cell[0]都有价值,它将触发一个事件.如果有null,它将改变的价值TextBox.

这是我的代码:

private void button1_Click(object sender, EventArgs e)
{
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if (dataGridView1.Rows[i].Cells[0].Value.ToString() == null)
        {
            textbox.Text = "null";
            break;
        }
        else 
        {
            MessageBox.Show("No null");
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是这里发生的事情是例如我有3行DataGridView,如果第一行不是null,它将在午餐时间MessageBox.我希望MessageBox在所有行的单元格都不为空时触发.

c# for-loop datagridview winforms

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

使用 DisplayFor 启用复选框

我有一个用 ASP.NET MVC 5 制作的 Web 应用程序。在这个应用程序中,我有一个显示信息列表的视图。

在这个列表中,我显示了一个boolean带有的信息@Html.DisplayFor(modelItem => item.valide)。所以 aCheckBox显示出来,它被选中和禁用。

我该怎么做才能disabled="disabled"从 中删除CheckBoxes

c# checkbox asp.net-mvc displayfor

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

SqlConnection为null但为什么?

我想连接到我的GuvenliBilgisayarim数据库.但是baglanti为空 - 为什么?

我的代码是:

SqlConnection baglanti = new SqlConnection("Data Source=DILEKZ\\SQLEXPRESS;Initial Catalog=GuvenliBilgisayarim;Integrated Security=True");

private void btn_giris_Click(object sender, EventArgs e)
{
    baglanti.Open();
    SqlCommand komut = new SqlCommand("select * from Login where kullanici_adi='" + txt_kulAdi.Text + " and kullanici_sifre=" + txt_sifre.Text +"',baglanti");
    komut.Connection = baglanti;

    SqlDataReader dr = komut.ExecuteReader();

    if (dr.Read())
    {
        Rapor rpr = new Rapor();
        rpr.Show();
    }
    else
    {
        MessageBox.Show("Kullan?c? ad? veya ?ifre yanl??");
    }

    dr.Close();
}
Run Code Online (Sandbox Code Playgroud)

.net c# sql sql-server ado.net

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

为什么我无法创建对象实例?

我需要添加对象列表,但我无法理解如何正确地做到这一点.我从控制台获得的每个新对象.怎么解决?

我的尝试:

namespace ExampleCars
{
    public class Car
    {
        public string name;
        public int speed;
        public Car(string name, int speed)
        {
            this.name = name;
            this.speed = speed;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string name;
            int speed, elements;
            List<Object> cars = new List<Object>();

            elements = Convert.ToInt32(Console.ReadLine());
            if (elements > 0)
            {                
                for (int i = 0; i < n; i++)
                {                    
                    name = Convert.ToString(Console.ReadLine());                    
                    speed = Convert.ToInt32(Console.ReadLine());                    
                    Car newCar = new Car(name, speed);
                    cars.Add(newCar);
                }
            } …
Run Code Online (Sandbox Code Playgroud)

.net c# oop class

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

如何将字符串列表连接在一起,并在每个值之间使用逗号?

我需要有关此代码的帮助。我想像这样在 foreach 循环中分割单词,但我不想,在最后一个单词之后出现。有什么建议么?

var listOtherWords = (from o in Words
                      where !o.ToUpper().StartsWith("A")
                      where !o.ToUpper().StartsWith("B")
                      where !o.ToUpper().StartsWith("C")
                      select o).ToList();

Console.WriteLine();
Console.Write("Other Words: ");

foreach (string o in lisOtherWords)
{
    Console.Write(o + " ,");
}

Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

.net c# linq string

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

空条件运算符对委托和常规对象的功能是否相同?

参考

我目前正在处理一些线程敏感代码。

在我的代码中,我有一个由两个不同线程操纵的对象的列表。一个线程可以将对象添加到此列表,而另一个线程可以将其设置为null。

在上面的参考中,它特别提到了代表:

myDelegate?.Invoke()
Run Code Online (Sandbox Code Playgroud)

等效于:

var handler = myDelegate;
if (handler != null)
{
    handler(…);
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,这种行为与a相同List<>吗?例如:

是:

var myList = new List<object>();    
myList?.Add(new object());
Run Code Online (Sandbox Code Playgroud)

保证等同于:

var myList = new List<object>();

var tempList = myList;
if (tempList != null)
{
    tempList.Add(new object());
}
Run Code Online (Sandbox Code Playgroud)


编辑:

请注意,两者之间(代理的工作方式)有所不同:

var myList = new List<int>();
var tempList = myList;
if (tempList != null)
{
    myList = null; // another thread sets myList to null here
    tempList.Add(1); // doesn't crash
}
Run Code Online (Sandbox Code Playgroud)

和 …

.net c# delegates null-conditional-operator

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