我感觉自己像一个总的菜鸟问这个,但无论如何,它在这里:
我想知道从不同线程同步事件的最简单方法是什么.
一些示例代码:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("# started on:" + Thread.CurrentThread.ManagedThreadId);
tt t = new tt();
t.First += new EventHandler(t_First);
t.Second += new EventHandler(t_Second);
Task task = new Task(new Action(t.Test));
task.Start();
while (true)
{
Console.ReadKey();
Console.WriteLine("# waiting on:" + Thread.CurrentThread.ManagedThreadId);
}
}
static void t_Second(object sender, EventArgs e)
{
Console.WriteLine("- second callback on:" + Thread.CurrentThread.ManagedThreadId);
}
static void t_First(object sender, EventArgs e)
{
Console.WriteLine("- first callback on:" + Thread.CurrentThread.ManagedThreadId);
}
class tt
{
public tt() …Run Code Online (Sandbox Code Playgroud) 我有一个基本上像这样设置的视图:
<Grid>
<ViewBox>
<Grid>
<ItemsControl ItemsSource="{Binding MyItems}"
ItemTemplate="{Binding Source={StaticResource MyItemsDataTemplate}}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
</ViewBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
这里使用的DataTemplate可以简化为:
<DataTemplate x:Key="AreaItemDisplayDataTemplate">
<Canvas Grid.ZIndex={Binding Z}>
<Grid>
// an shape is displayed here...
</Grid>
</Canvas>
Run Code Online (Sandbox Code Playgroud)
我现在希望ZIndex绑定到各个项目的Z属性.当我调试代码时,我也可以看到,当我期望它时,访问Z属性getter(每当我为它举起propertychanged事件时),所以我假设绑定工作正常.
但是,ZIndex没有按预期工作.绑定到该值对实际显示的Z Order没有影响.这个代码我哪里错了?
我正在使用RestSharp与远程服务器通信.我收到一个JSON序列化字符串,我可以反序列化为ac#对象.我也能够将json数组反序列化为List.但是,我希望这些对象在WPF绑定中使用,所以我需要将它们放在ObservableCollection中以方便使用.但是,如果我尝试将属性从List更改为ObservableCollection(或IList,或ICollection或Collection),则会在反序列化时出现异常.
Unable to cast object of type 'RestSharp.JsonArray' to type 'System.Collections.Generic.IDictionary`2[System.String,System.Object]
Run Code Online (Sandbox Code Playgroud)
底层代码真的不是特别的,但无论如何它在这里:
private ObservableCollection<StationDto> stations;
[JsonProperty(PropertyName = "stations")]
public ObservableCollection<StationDto> Stations
{
get { return this.stations; }
set
{
this.stations = value;
RaisePropertyChanged(() => Stations);
}
}
Run Code Online (Sandbox Code Playgroud)
我知道接口不起作用,因为Json.net需要一个具体的类来序列化.
我已经做了相当多的谷歌搜索,但我还没有看到解决方案.是否有一种常用于json/rest服务的手工代理的模式?
我希望有一个TabControl多重TabItems.这些TabItems各有一个标题文本.这些文本的长度可能有很大差异(如5个字符长和15个字符长).
我希望TabControl仅将标题排成一行.
所有选项卡标题应使用相同的宽度,并且当有足够的可用空间时,我希望它们使用所有可用空间,最多为a MaxWidth,对所有项目都相同.
因此,如果我想对7个项目使用100的vMaxWidth`,则标签标题的宽度最大为700.如果有更多可用空间,则应忽略它.
如果可用空间较少,我希望在项目之间平均分配该空间.如果文本被切断,我想使用TextWrapping.
我现在尝试了多种解决这个问题的方法,这是我目前的设置:
<Style x:Key="Style-TabControl-Main" TargetType="{x:Type TabControl}">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TabControl}">
<Grid KeyboardNavigation.TabNavigation="Local">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Border BorderThickness="0,0,0,1" Margin="13,0,0,0" BorderBrush="{StaticResource Brush-White}">
<StackPanel Panel.ZIndex="1" x:Name="HeaderPanel" IsItemsHost="True" KeyboardNavigation.TabIndex="1" Background="Transparent"
Orientation="Horizontal"/>
</Border>
<Border x:Name="Border"
Grid.Row="1" Grid.ColumnSpan="2"
KeyboardNavigation.TabNavigation="Local"
KeyboardNavigation.DirectionalNavigation="Contained"
KeyboardNavigation.TabIndex="2"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" /> …Run Code Online (Sandbox Code Playgroud) Background: I would like to use System.Linq.Dynamic library to post In/Contains query to MS SQL
Please note I am trying to use System.Linq.Dynamic in generic function so that I could apply customer filter to any class having CustomerId(integer) property. Also CustomerId property could be nullable
All SO posts redirects me to this solution. After implementing the same I keep getting this exception: "No generic method 'Contains' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No …
我在我的项目中使用PrimeFaces作为Web技术.我有一个注册表,用户注册自己.在该表单中,用户还可以附加一些文档.到目前为止没有问题.但是当用户填写表单并附上一些文档时,用户可以通过下载来检查附件.为了提供下载文件,我使用fileDownload和commandButton.它运行正常,但问题是当用户想要下载附件时,表单已经过验证!因此,如果表单中的任何字段未经过验证,则用户无法下载任何文件!我想为用户提供机会,以便他可以在填写表单的字段之前先附加文档并检查它们.如果有人能帮助我,我非常感激.
我希望能够做到以下几点:
示例:我有一个包含三列的文件("type","value","message")
我想使用flatfile目标逐行导入该文件.然后我想做条件拆分.如果"type"列的值为"1",我想将该行写入我的destinatoin.如果类型是"2"或"3"我想忽略它们.但是,如果它的"A"或"0"我想要失败组件.
除了"失败"之外,我还有其他一切.我将最后一个条件("列不是1,2或3")的输出配置为"Fail Component",但它实际上并没有使组件失败.
c# ×4
wpf ×2
xaml ×2
.net-4.0 ×1
bids ×1
binding ×1
datatemplate ×1
download ×1
json.net ×1
linq ×1
primefaces ×1
restsharp ×1
ssis ×1
tabcontrol ×1
task ×1
validation ×1