我的按钮有一个标准样式,但我希望样式的某些部分是可配置的.例如,当按钮触发MouseOver时,我会出现边框,我希望边框颜色可配置.
下面这篇文章:http://www.thomaslevesque.com/2011/10/01/wpf-creating-parameterized-styles-with-attached-properties/我以为我可以使用附加属性和TemplateBinding来实现这一目标.
我创建了以下附加属性:
public static class ThemeProperties
{
public static Brush GetButtonBorderColour(DependencyObject obj)
{
return (Brush)obj.GetValue(ButtonBorderColourProperty);
}
public static void SetButtonBorderColour(DependencyObject obj, Brush value)
{
obj.SetValue(ButtonBorderColourProperty, value);
}
public static readonly DependencyProperty ButtonBorderColourProperty =
DependencyProperty.RegisterAttached(
"ButtonBorderColour",
typeof(Brush),
typeof(ThemeProperties),
new FrameworkPropertyMetadata(Brushes.Black, FrameworkPropertyMetadataOptions.Inherits));
}
Run Code Online (Sandbox Code Playgroud)
我这样设置属性:
<Button Style="{StaticResource RedButton}" local:ThemeProperties.ButtonBorderColour="#B20000"/>
Run Code Online (Sandbox Code Playgroud)
我的风格看起来像这样:
<Window.Resources>
<Style x:Key="RedButton" TargetType="Button">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="FontFamily" Value="Tahoma"/>
<Setter Property="FontSize" Value="11px"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="MinHeight" Value="25" />
<Setter Property="FocusVisualStyle" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ServiceStack以RESTful方式将文件返回到ServiceStack客户端.
我已经阅读了有关SO(此处和此处)的其他问题,建议使用HttpResult和FileInfo对象或MemoryStream来允许将ContentType标头更改为相关的文件类型.
当我通过浏览器调用服务时,这对我有用,正确的文件会自动开始下载.我如何使用其中一个ServiceStack客户端使用该文件?
我正在使用Request DTO并尝试使用类似的东西返回
return new HttpResult(new FileInfo("file.xml"), asAttachment:true) {
ContentType = "text/xml"
};
Run Code Online (Sandbox Code Playgroud)
例如,如何使用JsonServiceClient消耗它?
首先,如果这是一个明显的重复道歉,我搜索了可能产生结果的所有短语,但努力寻找答案/连贯地构建我的搜索术语.
我有一个集合1和一个对象A的集合2.
// Object A Structure
Date
Type
Value
Run Code Online (Sandbox Code Playgroud)
集合1涵盖2种类型的日期1到2,集合2涵盖1种类型的日期3到4:
// Collection 1
[0] = 1st, TypeA, 3
[1] = 2nd, TypeA, 3
[2] = 1st, TypeB, 57
[3] = 2nd, TypeB, 57
// Collection 2
[0] = 3rd, TypeB, 57
[1] = 4th, TypeB, 58
Run Code Online (Sandbox Code Playgroud)
我最初的要求是结合这两个集合.没问题:
var result = collection1.Union(collection2);
Run Code Online (Sandbox Code Playgroud)
但是,我现在希望将两个集合组合在一起,但不包括Collection 1中的对象,其中Collection 2中不存在Type:
// Result Collection
[0] = 1st, TypeB, 57
[1] = 2nd, TypeB, 57
[2] = 3rd, TypeB, 57
[3] = 4th, TypeB, 58
Run Code Online (Sandbox Code Playgroud)
我确信这是一个简单的(希望是linq)一线解决方案,但我无法让我的大脑明白它是什么.
我到目前为止最好的(两条线)是:
// …Run Code Online (Sandbox Code Playgroud)