我想创建一些我常用的WPF控件的库,其中一个控件是CustomWindow继承自Window类的控件.如何让我CustomWindow使用库中定义的默认外观?
我可以替换
<Window x:Class="..." />
Run Code Online (Sandbox Code Playgroud)
同
<MyControls:CustomWindow x:Class="..." />
Run Code Online (Sandbox Code Playgroud)
它适用于窗口行为,但不适用于出现.
编辑
这是我到目前为止的简化版本:
自定义窗口控件.位于控制库中.
public class CustomChromeWindow: Window
{
static CustomChromeWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomChromeWindow),
new FrameworkPropertyMetadata(typeof(CustomChromeWindow)));
}
}
Run Code Online (Sandbox Code Playgroud)
窗口风格.位于Generic.xaml中,是控件库的Themes文件夹中的ResourceDictionary
<Style TargetType="local:CustomChromeWindow">
<Setter Property="WindowStyle" Value="None" />
<Setter Property="Background" Value="Red" />
</Style>
Run Code Online (Sandbox Code Playgroud)
测试窗口.引用控件库的单独项目的启动窗口
<local:CustomChromeWindow
x:Class="MyControlsTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyControls;assembly=MyControls"
Title="MainWindow" Height="350" Width="525"
>
<Grid>
<TextBlock Text="This is a Test" />
</Grid>
</local:CustomChromeWindow>
Run Code Online (Sandbox Code Playgroud)
我最终获得的是一个带有常规WindowStyle和黑色背景的窗口.
我想知道PropertyChanged当用户在输入文本时暂停时是否可以引发事件TextBox?或者更具体地说,我想X在用户停止在TextBox中键入数秒后运行一个方法.
例如,我有一个带有TextBox的表单,没有别的.用户在TextBox中键入1-9位Id值,相当资源密集的后台进程加载记录.
我不想使用,UpdateSouceTrigger=PropertyChanged因为这会导致资源密集型后台进程在键入字符时运行,因此9位ID号从这些进程中的9个开始.
我也不想使用,UpdateSourceTrigger=LostFocus因为表单上没有任何其他内容可以使TextBox失去焦点.
那么有没有办法让我的后台进程只有在用户输入ID号时暂停后才会运行?
是否有替代使用.Contains()选择实体框架中存在于指定列表中的对象?Contains()如果您的列表很小,那么效果很好,但是一旦您开始获得几千个项目,性能就会很糟糕.
return (from item in context.Accounts
where accountIdList.Contains(item.AccountId)
select item).ToList();
Run Code Online (Sandbox Code Playgroud)
我正在使用EF 4.0,.Net Framework 4.0和SQL Server 2005.我不反对SQL解决方案,因为EF生成的查询只需要一秒钟就SQL运行大约10k项目.
我有一个第三方程序,该程序坚持使用重写某些SQL语句UCase(value)。UCase不被SQL Server 2005支持,所以我想我可以创建一个User-Defined-Function来返回UPPER(value)并为其分配Alias UCase,但是看来我仍然需要使用[dbo].[Alias]
是否可以在没有[dbo]前缀的情况下调用User-Defined-Function ?还是有办法让SQL运行SELECT UCase('abc')为SELECT UPPER('abc')?
对于我来说,为数据输入表单的样式编写类似的东西并不罕见,但我的问题是,TextBox并且TextBlock似乎没有实现在中的Setter BaseElementStyle.通常我需要单独定义它们.
为什么是这样?它有办法吗?
我猜它与其他控件模板中常用的事实有关(例如,TextBlock用于大多数控件,TextBox用于DatePickers和ComboBoxes)
<Style x:Key="BaseElementStyle" TargetType="{x:Type FrameworkElement}">
<Setter Property="Margin" Value="5" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type Label}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type ComboBox}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type DatePicker}" BasedOn="{StaticResource BaseElementStyle}" />
<Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource BaseElementStyle}" />
Run Code Online (Sandbox Code Playgroud) 我有一个ListBox风格使用RadioButtons,并更改它SelectedItem也会更改UserControl显示在它ContentControl下面.该应用程序如下所示:

<ListBox ItemsSource="{Binding AvailableViewModels}"
SelectedItem="{Binding SelectedViewModel}"
Style="{StaticResource RadioButtonListBoxStyle}" />
<ContentControl Content="{Binding SelectedViewModel}" />
Run Code Online (Sandbox Code Playgroud)
我的问题是UserControls每个都包含一个自定义的网格控件(Telerik RadGridView),由于它包含的数据量,它在加载时有明显的延迟.
我在Grid加载后ItemsSource在Loaded事件中设置绑定以防止UI在Grid加载时锁定,但无论我如何尝试运行它,RadioButtons仍然反映加载时的延迟,这给出了冻结的错觉UI

我尝试使用尽可能低的DispatcherPriority来设置绑定,但它似乎没有什么区别.
XAML:
<telerik:RadGridView x:Name="MyGrid" Loaded="MyGrid_Loaded" Unloaded="MyGrid_Unloaded">
<!--....-->
</telerik:RadGridView>
Run Code Online (Sandbox Code Playgroud)
C#:
private void MyGrid_Loaded(object sender, RoutedEventArgs e)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.SystemIdle,
new Action(delegate()
{
BindingOperations.SetBinding(
MyGrid,
RadGridView.ItemsSourceProperty,
new Binding("ViewModelProperty")
);
}));
}
private void MyGrid_Unloaded(object sender, RoutedEventArgs e)
{
MyGrid.ItemsSource = null;
}
Run Code Online (Sandbox Code Playgroud)
应该注意的是,每次UserControl加载时,它都会很好地加载,RadioButton选择立即改变,并在几秒钟后加载网格.它只能切换到一个UserControl …
有没有一种简单的方法可以将值分布在多行中?
例如,我的表包含
类型已开票已付电流 充电 100 0 100 充电 100 0 100 充电 100 0 100 付款 0 250 0 付款 0 25 0
数据是通过这种方式导入的,但我需要根据也导入的付款交易为该交易填充Current和Paid列。
有没有一种简单的方法来编写查询来确定Current每条记录的列的余额?
例如,250 会将 100 应用于前两条记录,50 应用于接下来的两条记录,而 25 将应用于最后一条,因此更新Current表中的余额后的最终结果应该是:
类型已开票已付电流 充电 100 100 0 充电 100 100 0 充电 100 75 25 付款 0 250 0 付款 0 25 0
理想情况下,我希望使用单个查询来执行此操作,而不是使用游标来单独处理每个项目。我一直在尝试通过使用Row_Number()函数并加入两个子查询来做到这一点,但我知道我在这里遗漏了一些东西
这是我的第一次尝试,结果得到了当前余额的运行总数
;with cte(invoiced, paid, current)
as (
select invoiced, paid, current
, row_number() over (order by …Run Code Online (Sandbox Code Playgroud) 我有两个巨大的(> 100000项)PathGeometry集合我需要使用PathGeometry.Combine进行比较,如下所示:
List<PathGeometry> firstList;
List<PathGeometry> secondList;
[...]
foreach (PathGeometry pg1 in firstList)
foreach (PathGeometry pg2 in secondList)
{
PathGeometry intergeo = PathGeometry.Combine(pg1, pg2, GeometryCombineMode.Intersect, null);
if (intergeo.GetArea() > 0)
{
// do whatever with intergeo.GetArea()
}
}
Run Code Online (Sandbox Code Playgroud)
令我惊讶的是,PathGeometry是GUI的一部分并使用调度程序,它有时会导致问题,因为我的计算在没有GUI的情况下在一些后台线程中运行使用Parallel.ForEach()
所以我正在寻找一种没有连接到GUI的PathGeometry的替代品.
我的数字非常复杂,并为PathGeometry.Figures添加了很多PathFigures.
我自己从一些臃肿的政府xml文件创建那些PathGeometries,所以创建其他东西也没有问题.但是我需要一个函数来创建这些几何中的两个(不是相互添加)的交集,以获得两个几何所覆盖的区域,例如此图中的红色区域:

如何将绑定的Html5数据属性添加到使用绑定生成的项目RadioButtonList?
我的代码看起来像这样:
<asp:Repeater Id="QuestionList" ...>
<ItemTemplate>
<asp:RadioButtonList DataSource='<%# Eval("Answers") %>'
SelectedValue='<%# Eval("SelectedAnswerId") %>'
DataTextField="Answer"
DataValueField="AnswerId"
Tag='<%# Eval("QuestionId") %>' />
</ItemTemplate>
</asp:Repeater>
Run Code Online (Sandbox Code Playgroud)
var List<Question> questions = GetQuestions();
QuestionList.DataSource = questions;
QuestionList.DataBind();
Run Code Online (Sandbox Code Playgroud)
它绑定到类结构,如下所示:
public class Question
{
int QuestionId;
string Question;
List<Answer> Answers;
}
public class Answers
{
int AnswerId;
string Answer;
bool SomeFlag;
}
Run Code Online (Sandbox Code Playgroud)
我需要添加SomeFlag到用于jQuery的UI,因此最终结果是生成的每个项应如下所示:
<input type="radio" data-flag="true" ... />
Run Code Online (Sandbox Code Playgroud)
有没有办法将html数据属性添加到从绑定生成的输入对象RadioButtonList?
我有一些代码循环遍历记录列表,为每个记录启动导出任务,每次任务完成时将进度计数器增加1,以便用户知道进程的距离.
但是根据我的循环的时间,我经常看到输出在较低的数字之前显示更高的数字.
例如,我希望看到这样的输出:
Exporting A Exporting B Exporting C Exporting D Exporting E Finished 1 / 5 Finished 2 / 5 Finished 3 / 5 Finished 4 / 5 Finished 5 / 5
但相反,我得到这样的输出
Exporting A Exporting B Exporting C Exporting D Exporting E Finished 1 / 5 Finished 2 / 5 Finished 5 / 5 Finished 4 / 5 Finished 3 / 5
我不希望输出是准确的,因为当我更新/使用它时我没有锁定值(有时它输出相同的数字两次,或跳过一个数字),但我不希望它倒退.
我的测试数据集是72个值,相关代码如下所示:
var tasks = new List<Task>();
int counter = 0;
StatusMessage = string.Format("Exporting …Run Code Online (Sandbox Code Playgroud) c# ×6
wpf ×5
sql ×2
xaml ×2
.net-4.0 ×1
asp.net ×1
basedon ×1
c#-4.0 ×1
coding-style ×1
dispatcher ×1
html5 ×1
inheritance ×1
mvvm ×1
pathgeometry ×1
styles ×1
t-sql ×1
task ×1
templates ×1
timer ×1
window ×1