在C#中,我有一个传递的功能T使用generics,我想运行一个检查,看看是否T是object一个实现了interface,如果这样称呼的一个methods上interface.
我不希望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'的隐式引用转换.
我加载了一个字符串列表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}"
他们是一种告诉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,它会在一个小窗口中打开相机应用程序
我用这个加载数据网格中的对象列表:
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但我不明白那里的代码,我无法解释如何我应该为我的问题转移那个.
我想在我的代码中更改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)
但语法高亮不会改变.我究竟做错了什么?对我的问题有更好的解决方案吗?
您可以禁用调整数据网格列的大小.
有没有办法停止调整行头高度的大小
此时用户可以调整行标题的大小.像这样:

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

这是我的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)
但这不起作用.那是结果:

有人知道解决方案吗?
我找到了一个例子,如何RichTextBox在Windows窗体中显示LineNumbers .
http://www.codeproject.com/Articles/38858/Line-Numbers-for-RichText-Control-in-C
在WPF中有人为它做一个例子吗?
编辑:
是否有人与AvalonEdit合作,因为他想在他的程序中显示LineNumbers并且可以通过我的问题帮助我.
我的问题是关于一个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) 我如何将 a 集中Inline在 a 中RichTextBox?
我FlowDocument从文本文件创建一个并将其加载到我的中,richTextBox1
并Inline根据 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) 我如何从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) 如何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) 我有一个包含列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# 和 .NET 进行编程,并且从未进一步使用过 c++ 或 c
你能给我一些开始的提示吗?
c# ×12
wpf ×7
datagrid ×2
richtextbox ×2
xaml ×2
attributes ×1
avalonedit ×1
camera ×1
database ×1
dll ×1
driver ×1
elapsed ×1
filter ×1
fluent ×1
focus ×1
generics ×1
interface ×1
line-numbers ×1
list ×1
listbox ×1
merge ×1
mvvm ×1
printing ×1
resize ×1
text-editor ×1
timer ×1
validation ×1
windows ×1