小编Kar*_*ann的帖子

在C#中,如果我的对象支持该接口,我如何检查T是否为IInterface类型并强制转换为?

在C#中,我有一个传递的功能T使用generics,我想运行一个检查,看看是否Tobject一个实现了interface,如果这样称呼的一个methodsinterface.

我不希望T只有该类型的约束.是否有可能做到这一点?

例如:

public class MyModel<T> : IModel<T> where T : MyObjectBase
{
    public IQueryable<T> GetRecords()
    {
        var entities = Repository.Query<T>();
        if (typeof(IFilterable).IsAssignableFrom(typeof(T)))
        {
            //Filterme is a method that takes in IEnumerable<IFilterable>
            entities = FilterMe(entities));
        }
        return entities;
    }

    public IEnumerable<TResult> FilterMe<TResult>(IEnumerable<TResult> linked) where TResult : IFilterable
    {
        var dict = GetDict();
        return linked.Where(r => dict.ContainsKey(r.Id));
    }
 }
Run Code Online (Sandbox Code Playgroud)

我得到的错误是:

错误21类型'TResult'不能在泛型类型或方法'FilterMe(System.Collections.Generic.IEnumerable)'中用作类型参数'TResult'.没有从'TResult'到'IFilterable'的隐式引用转换.

c# generics interface

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

WPF过滤ListBox

我加载了一个字符串列表ListBox,现在我想在我输入文本时过滤它TextBox.我该怎么做?

public void ListLoad()
{
    ElementList = new List<string>(); // creation a list of strings
    ElementList.Add("1"); // add a item of string
    ElementList.Add("2"); // add a item of string

    DataContext = this; // set the data context
}
Run Code Online (Sandbox Code Playgroud)

我在XAML中绑定它:

ItemsSource ="{Binding ElementList}"

c# wpf xaml listbox list

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

在Windows 10全屏使用CameraCaptureUI

他们是一种告诉CameraCaptureUI的方法,它应该以全屏模式启动,而不是一个小窗口?

我目前来自链接网站的代码:

CameraCaptureUI cameraUI = new CameraCaptureUI();

Windows.Storage.StorageFile capturedMedia =
    await cameraUI.CaptureFileAsync(CameraCaptureUIMode.Video);
Run Code Online (Sandbox Code Playgroud)

我的应用程序基于WinRT for Windows 8.1.

在Win 8客户端上,Camera App只是全屏启动,但是使用Win 10 Client,它会在一个小窗口中打开相机应用程序

c# camera windows-runtime

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

在WPF中筛选DataGrid

我用这个加载数据网格中的对象列表:

dataGrid1.Items.Add(model);
Run Code Online (Sandbox Code Playgroud)

model从数据库成为数据.它有一个Id(int),Name(string)Text(string)

在我的数据网格中,我只显示了该名称model.当我在文本框中输入内容时,如何现在过滤数据网格?

我在这个页面:http://msdn.microsoft.com/en-us/library/vstudio/ff407126(v=vs.100).aspx但我不明白那里的代码,我无法解释如何我应该为我的问题转移那个.

c# wpf datagrid filter

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

代码中的AvalonEdit更改语法突出显示

我想在我的代码中更改AvalonEdit的语法突出显示.

XAML:

 <avalonEdit:TextEditor Name="textEditor" SyntaxHighlighting="{Binding syntaxHighlighting}" />
Run Code Online (Sandbox Code Playgroud)

C#:

public string syntaxHighlighting { get; set; }

public MainWindow()
{
     InitializeComponent();
     syntaxHighlighting = "C#";
     DataContext = this;
}
Run Code Online (Sandbox Code Playgroud)

但语法高亮不会改变.我究竟做错了什么?对我的问题有更好的解决方案吗?

c# wpf syntax-highlighting text-editor avalonedit

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

DataGridRowHeader的CanUserResize = false

您可以禁用调整数据网格列的大小.

有没有办法停止调整行头高度的大小

此时用户可以调整行标题的大小.像这样:

古腾标签

我想禁用它.所以应该总是看:

在此输入图像描述

这是我的RowHeaderTemplate

         <DataGrid.RowHeaderTemplate>
            <DataTemplate>
                <DockPanel FlowDirection="LeftToRight" DataContext="{Binding Item,RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}}">
                    <TextBlock Text="{Binding ZimmerNummer}" MinWidth="48" MaxWidth="48" />
                </DockPanel>
            </DataTemplate>
        </DataGrid.RowHeaderTemplate>
Run Code Online (Sandbox Code Playgroud)

这是我的想法:

<DataGrid.RowHeaderStyle>
    <Style TargetType="DataGridRowHeader">
        <Setter Property="MaxHeight"
            Value="55"/>
    </Style>
</DataGrid.RowHeaderStyle>
Run Code Online (Sandbox Code Playgroud)

但这不起作用.那是结果:

在此输入图像描述

有人知道解决方案吗?

wpf datagrid resize

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

从WPF中的RichTextBox显示LineNumbers

我找到了一个例子,如何RichTextBox在Windows窗体中显示LineNumbers . http://www.codeproject.com/Articles/38858/Line-Numbers-for-RichText-Control-in-C

WPF中有人为它做一个例子吗?

编辑:

是否有人与AvalonEdit合作,因为他想在他的程序中显示LineNumbers并且可以通过我的问题帮助我.

c# wpf richtextbox line-numbers

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

将Fluent合并到main.exe后出现问题

我的问题是关于一个Fluent,我program.exe使用此代码与我在一个merged.exe中合并:

    public class Program
    {
        [STAThreadAttribute]
        public static void Main()
        {
            AppDomain.CurrentDomain.AssemblyResolve += OnResolveAssembly;
            App.Main();
        }

        private static Assembly OnResolveAssembly(object sender, ResolveEventArgs args)
        {
            //We dont' care about System Assemblies and so on...
            //if (!args.Name.ToLower().StartsWith("wpfcontrol")) return null;

            Assembly thisAssembly = Assembly.GetExecutingAssembly();

            //Get the Name of the AssemblyFile
            var name = args.Name.Substring(0, args.Name.IndexOf(',')) + ".dll";

            //Load form Embedded Resources - This Function is not called if the Assembly is in the Application Folder
            var resources = thisAssembly.GetManifestResourceNames().Where(s …
Run Code Online (Sandbox Code Playgroud)

c# wpf dll merge fluent

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

如何将 RichTextBox 子级的内联带入视图

我如何将 a 集中Inline在 a 中RichTextBox
FlowDocument从文本文件创建一个并将其加载到我的中,richTextBox1Inline根据 Button_click一个接一个地标记(重新创建FlowDocument

使用此代码:

            richTextBox1.SelectAll();
            richTextBox1.Selection.Text = "";

            string text = System.IO.File.ReadAllText(file);
            int iZeile = 0;

            string[] split = text.Split(new string[] {"\r\n"},StringSplitOptions.None);

                    foreach (string s in split)
                    {
                        if (iZeile != 27)
                        {
                            paragraph.Inlines.Add(s + "\r\n"); // adds line added without marking
                        }
                        else
                        {
                            Run run = new Run(split[27]); // adds line with marking
                            run.Background = Brushes.Yellow;
                            paragraph.Inlines.Add(run);
                            paragraph.Inlines.Add("\r\n");
                        }
                        iZeile++;
                    }

            FlowDocument …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml focus richtextbox

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

如何在MVVM中捕获DataAnnotations验证

我如何从DataAnnotations中捕获验证?我在这里研究,但我不明白它是如何工作的

所以我跳了一些你可以启发我的

这是我目前的测试代码:

模型

public class Person // Represents person data.
{
    /// <summary>
    /// Gets or sets the person's first name.
    /// </summary>
    /// <remarks>
    /// Empty string or null are not allowed.
    /// Allow minimum of 2 and up to 40 uppercase and lowercase.
    /// </remarks>
    [Required]
    [RegularExpression(@"^[a-zA-Z''-'\s]{2,40}$")]        
    public string FirstName{ get; set;}

    /// <summary>
    /// Gets or sets the person's last name.
    /// </summary>
    /// <remarks>
    /// Empty string or null are not allowed.
    /// </remarks>
    [Required] …
Run Code Online (Sandbox Code Playgroud)

c# validation attributes mvvm data-annotations

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

在静态方法中使用其他方法

如何ChangeText在静态方法中使用该方法timer_Elapsed

public Load()
{
    InitializeComponent();

    System.Timers.Timer timer = new System.Timers.Timer();
    timer.Interval = 1000;

    // I can't transfer parameters here
    timer.Elapsed += new ElapsedEventHandler(timer_Elapsed); 
    timer.Start();
}

static void timer_Elapsed(object sender, ElapsedEventArgs e)
{
    //Its underlined in red. I need a object reference?
    ChangeText(); 
}

public void ChangeText()
{
    label1.Text = label1.Text + ".";
}
Run Code Online (Sandbox Code Playgroud)

c# timer elapsed

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

MSSQL WHERE日期对象的函数

我有一个包含列id(int)和列的表,HolidayDate(Date)我想在列表中获取特定月份的假期.当我得到所有假期的列表时,我知道如何在代码中执行此操作.

但我想从数据库(MSSQL Express 2010)获取筛选列表.当我给存储过程指定年份和月份时,是否有一种方法可以过滤存储过程中的Date-Object

例如,这不起作用:

SELECT        Id, HolidayDate
FROM            dbo.Holiday
WHERE        (HolidayDate= '*.11.2013')
Run Code Online (Sandbox Code Playgroud)

(因为从*.11.2013转换为Date-Object不起作用)

......这项工作:

SELECT        Id, HolidayDate
FROM            dbo.Holiday
WHERE        (HolidayDate= '22.11.2013')
Run Code Online (Sandbox Code Playgroud)

我只是不想加载所有假期的完整列表并在我的程序中过滤它们

c# database stored-procedures

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

Windows 打印机驱动程序

我们目前购买了一个用于计算等的程序,但我们不允许双面打印。但我们真正的打印机确实支持它。

我想问是否可以在应用程序和真实打印机之间设置“打印机驱动程序”,我也可以发送文档。在这个驱动程序中,我说它应该以双面打印。

我目前仅使用 C# 和 .NET 进行编程,并且从未进一步使用过 c++ 或 c

你能给我一些开始的提示吗?

c# windows printing driver

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