RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-343615

AlanAugust's questions

Martin Hope
DiMaAgalakov
Asked: 2023-06-29 16:44:49 +0000 UTC

按类型从类中获取集合

  • 5

有一个带有集合的类:

public class CollectionsStorage
{
   public ObservableCollection<Car> Cars { get; set; } = new();

   public ObservableCollection<Animal> Animals { get; set; } = new();

   // Тип "T" это Animal или Car.
   public IEnumerable<T>? GetObjects<T>()
   {
     // Здесь надо вернуть коллекцию определённого типа.
   }
}
c#
  • 1 个回答
  • 59 Views
Martin Hope
AlanAugust
Asked: 2022-08-26 15:51:58 +0000 UTC

MVVM。IsEnabledMenuItem

  • 0

我有一个菜单:

<Button.ContextMenu>
                    <ContextMenu Placement="Bottom">
                        <MenuItem Header="H"  Command="{Binding AddCommand1}"/>
                        <MenuItem Header="H1" Command="{Binding AddCommand2}"/>
                        <MenuItem Header="H2"  Command="{Binding AddCommand3}"/>
                        <MenuItem Header="H3"  Command="{Binding AddCommand4}"/>
                        <MenuItem Header="H4" Command="{Binding AddCommand5}"/>
                    </ContextMenu>
                </Button.ContextMenu>

还有一些方法:

private void Method()
    {

       
    }

如何为该方法中的最后一个菜单项设置 IsEnabled?

c#
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-05-22 14:37:34 +0000 UTC

使用 ListBox 元素的 CheckBox。可观察集合

  • 1

我有一个 ListBox c ObservableCollection<Model> Models。ListBox 有一个 CheckBox 有一个绑定IsVisualizationModel

看法:

<Window.Resources>
     <local:Model x:Key="models"/>
</Window.Resources>
<ListBox ItemsSource = "{Binding Models}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                        <CheckBox IsChecked="{Binding Source={StaticResource models}, Path=IsVisualizationModel}"/>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

模型:

 public class Model : INotifypropertyChanged
 {
    private bool isVisualizationModel;
    public bool IsVisualizationModel
    {
        get { return isVisualizationModel; }
        set
        {
            isVisualizationModel = value;
            OnPropertyChanged();
        }
    } 
// interface implementation
 }

问题是我有一个完整的模型列表,然后在代码中我遍历它,检查 IsVisualizationModel 属性。检查时,我总是得到假,尽管绑定触发并将属性设置为真。显然,绑定更改了非当前列表项(ObservableCollection 模型)的属性。可能值得使用 ICommand 以某种方式传递特定的列表实例并更改它的 IsVisualizationModel 属性。我不知道如何正确实施。此外,我这里没有涉及 ViewModel,这对我来说似乎也是错误的。

c#
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-05-08 18:22:08 +0000 UTC

ICommand 接口。如何将实例传递给方法参数?

  • 1

我正在使用 MVVM。有一个列表,单击按钮即可<Button Command="{Binding AddKernel}"/>添加项目。

(查看)列表:

<StackPanel Grid.Column="0" Grid.Row="1" VerticalAlignment="Top" >
        <ListBox ItemsSource = "{Binding Kernels}" HorizontalAlignment="Stretch">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="5">
                        <Button Command="{Binding RemoveKernel}" Content="Delete" Margin="5" Width="40" Height="18" VerticalAlignment="Center" />
                        <TextBlock  Text="{Binding Title}" Margin="5" FontSize="16" VerticalAlignment="Center" />
                        <CheckBox IsChecked="{Binding IsVisualizationKernel}" Margin="5" FontSize="16"  VerticalAlignment="Center" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </StackPanel> 

(模型)模型有一个应该删除列表项的方法。我需要将一个内核实例传递给这个方法的参数。

public static void RemoveKernel(object kernel)
    {
        if (kernel is Kernel)
        {
            Kernels.Remove((Kernel)kernel);
        }
        else
        {
            System.Console.WriteLine("TRIWOGA!!!");
        }
    } 

(ViewModel) 我这样称呼这个方法:

public ICommand RemoveKernel
    {
        get
        {
            return new RelayCommand(Well.RemoveKernel);
        }
    }

我不知道如何将内核实例传递给 RemoveKernel 方法参数?

c#
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-05-04 21:13:30 +0000 UTC

访问 MainWindow 类之外的 XAML 元素

  • 0

我正在使用 MVVM。有一个 XAML 元素具有自己的Name="nameElement". 我只能从 MainWindow 类访问它,但我不想在这个类中编写额外的代码。

例如:有一个 ListBox 与Name="kernelList"

看法:

<ListBox x:Name="kernelsList" SelectionChanged="kernelsList_SelectionChanged" Margin="160,0,41,10">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <StackPanel Margin="5" Orientation="Horizontal">
                    <TextBlock Margin="5" FontSize="16" Text="{Binding Name}" HorizontalAlignment="Center" />
                    <CheckBox Margin="5" FontSize="16" IsChecked="{Binding IsVisualization}" HorizontalAlignment="Center" />
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>

我只能访问MainWindow 类中的“kernelList” 。假设我想向列表中添加一个项目

kernelsList.ItemsSource = Kernels;

如何从其他类访问 XAML 元素?

c#
  • 3 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-12-06 19:20:13 +0000 UTC

应该抓住什么回报?

  • 0

这是我的代码:

// Чтение из файла
    private string ReadFile(string pathFile)
    {
        try
        {
            using (StreamReader streamReader = new StreamReader(pathFile))
            {
                string textFile = streamReader.ReadToEnd();
                return textFile;
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }

当然,方法名是ReadFile()用红色下划线的,因为不是所有的代码行都返回一个值。应该抓住什么回报?还是我写错了什么?

c#
  • 3 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-11-25 15:18:46 +0000 UTC

Visual Studio 2019 中的断点

  • 1

如何使用断点查看变量中的数据?以前,它们显示在下面的窗口中,但现在我找不到了。

отладка
  • 2 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-11-18 15:26:56 +0000 UTC

C# 线程。需要方法名,,,

  • -3
    for (int i = 0; i < n_thread; i++)
        {
            Thread myThread = new Thread(new ThreadStart(Count(i, n_thread, a, b, c)));
            myThread.Start();
            Thread.Sleep(1000);
  }

这是计数方法

 public static void Count(int id, int n_thread, float[][]a, float[][] b, float[][] c)
    {

    }

发誓 (Count(i, n_thread, a, b, c)

错误:“需要方法名称”

c#
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-11-18 10:23:52 +0000 UTC

LINQ 中 LIKE(子字符串搜索)的类似物

  • 2

如何将此查询更改为类似

WHERE movie.Title LIKE "searchString"

也就是说,搜索子字符串,而不是整个字符串。

 public async Task<IActionResult> Index(string searchString)
    {
        IEnumerable<Movie> MovieQuery =
            from movie in db.Movie
            where movie.Title == searchString
            select movie;

        return View(MovieQuery);
    }
c#
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-10-14 16:46:05 +0000 UTC

为电影数据库创建表

  • 1

我需要数据库中的每部电影(电影表)与一个或多个演员(演员表)相关联。

也就是说,我想在电影表的演员字段中有一个演员列表,但同时我想用演员(演员)创建一个单独的表,以便它引用电影表。

怎么做?

sql
  • 1 个回答
  • 10 Views
Martin Hope
AlanAugust
Asked: 2020-09-20 16:34:42 +0000 UTC

在 C# 中处理进程

  • 2

如何获取当前进程使用的 RAM 量?

c#
  • 2 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5