我希望能够在WPF窗口中的.cs文件中设置样式属性(和值).
我的问题是,如果我有30个矩形,所有这些矩形我想要具有相同的样式(我不想单独更新所有矩形).我想将它们全部设置(在xaml文件中)为相同的样式,然后更新样式以按照我喜欢的方式.
假设我Style = "key1"在每个矩形的Xaml中设置.然后我希望能够稍后修改"key1",以便所有矩形都能反映出这种变化.
我试过了 App.xaml
<Application.Resources>
<Style x:Key="key1" TargetType="Rectangle">
<Setter Property="Fill" Value="Red"/>
</Style>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
在MainwWindows.xaml中
<StackPanel>
<Rectangle Style="{StaticResource key1}" Height="200" Width="200" x:Name="rect1"/>
<Button Click="Button_Click" Content="Click"/>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
在代码背后
private void Button_Click(object sender, RoutedEventArgs e)
{
Style style = Application.Current.Resources["key1"] as Style;
style.Setters.Add(new Setter(Rectangle.VisibilityProperty, Visibility.Collapsed));
}
Run Code Online (Sandbox Code Playgroud)
这会更新样式但不会更新矩形.
这可能吗?有谁知道如何做到这一点?(非常感谢一个例子).
我有一个方法,我想转换为扩展方法
public static string GetMemberName<T>(Expression<Func<T>> item)
{
return ((MemberExpression)item.Body).Member.Name;
}
Run Code Online (Sandbox Code Playgroud)
并称之为
string str = myclass.GetMemberName(() => new Foo().Bar);
Run Code Online (Sandbox Code Playgroud)
所以评估为 str = "Bar"; // It gives the Member name and not its value
现在,当我尝试将此转换为扩展方法时
public static string GetMemberName<T>(this Expression<Func<T>> item)
{
return ((MemberExpression)item.Body).Member.Name;
}
Run Code Online (Sandbox Code Playgroud)
并称之为
string str = (() => new Foo().Bar).GetMemberName();
Run Code Online (Sandbox Code Playgroud)
错误说 Operator '.' cannot be applied to operand of type 'lambda expression'
我哪里错了?
我可以将今天的日期放在标签中而不用xaml绑定它,比如说
<Label Text="DateTime.Now, StringFormat='{0:MMMM dd, yyyy}'"/>
Run Code Online (Sandbox Code Playgroud)
谢谢
例如,我已设置timer1.Interval为5000,并且我想知道在计时器计时之前该间隔还剩多少时间。我怎样才能做到呢?
我们都知道,如果SQL用户定义的表值类型(UDT)具有依赖项/依赖项,则不能删除它们.对.
但是,即使他们有家属,今天我也放了一个.唯一的标准是它们不应该用作DB对象的参数,如proc或func.
CREATE TYPE FooUDT AS TABLE
(
ID int NOT NULL
)
Run Code Online (Sandbox Code Playgroud)
依赖的
CREATE PROCEDURE Bar
as
BEGIN
DECLARE @Identifier FooUDT
--Some operations on @Identifier
END
GO
Run Code Online (Sandbox Code Playgroud)
的FooUDT,因为它使用了proc中,而不是一个参数可以被丢弃.但是跟随方式它不能被丢弃.
CREATE PROCEDURE Bar
@Identifier FooUDT readonly
as
BEGIN
--Some operations on @Identifier
END
GO
Run Code Online (Sandbox Code Playgroud)
更有趣的是,在这两种情况下,如果我们检查依赖关系,两者都会显示彼此的名称.然而,前一种情况可以被取消,但后者则不然.为什么这个?或者我错过了什么?
我正在将很多代码从VB.net转换为c#,这是我认为在转换过程中出现的另一个问题.
if (sRow.Cells[1].Value == true)
Worked = "X";
else if (sRow.Cells[2].Value == true)
Vacation = "X";
else if (sRow.Cells[3].Value == true)
Sick = "X";
else if (sRow.Cells[4].Value == true)
Holiday = "X";
Run Code Online (Sandbox Code Playgroud)
在每个if/else/else if行上它给我这个错误.我确定我错过了一些会迫使我做头脑的东西......
错误7运算符'=='无法应用于'object'类型和'bool'类型的操作数
今天我在一台新机器上安装了Visual Studio 2010.
当第一次启动VS2010时,它询问"默认环境窗口"我错误地选择了"Visual C#开发设置".

但现在我想将该设置更改为"Visual Basic开发设置".我怎么能这样做?
我有一个困惑
场景:
我想创建一个DataTable的副本,以添加到另一个DataSet.有两种方法(AFAIK):
1. Make a Copy using DataTable.Copy()
2. Make a Deep Clone using
public static T DeepClone<T>(this T source)
{
if (!typeof(T).IsSerializable)
throw new ArgumentException("The type must be serializable.", "source");
// Don't serialize a null object, simply return the default for that object
if (Object.ReferenceEquals(source, null))
return default(T);
IFormatter formatter = new BinaryFormatter();
Stream stream = new MemoryStream();
using (stream)
{
formatter.Serialize(stream, source);
stream.Seek(0, SeekOrigin.Begin);
return (T)formatter.Deserialize(stream);
}
}
Run Code Online (Sandbox Code Playgroud)
我的困惑:
DataTable.Copy()在内部使用DeepClone或一些其他的逻辑是什么?我覆盖了 ResourceDictionary 中控件的模板Generic.xaml。我添加了一个按钮,我想在上面添加一些事件。
<Setter Property="Template">
<Setter.Value>
--Added my button here.
</Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)
所以在加载控制事件中我做了
Button b = (Button)mycontrol.Template.FindName("PARTName", mycontrol)
//Add Events on my button
Run Code Online (Sandbox Code Playgroud)
我在互联网上读到的一些我可以做的地方
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
UIElement editingelement = GetTemplateChild("PART_EditingElement");
if (editingelement != null)
{
// do something
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试做这个建议时GetTemplateChild说不要使用。

所以我的问题是
为什么不使用GetTemplateChild. 它过时了吗?和
FrameWorkTemplate.FindName和 和有ControlTemplate.FindName什么区别?
我有一个源表
select 54371 Id, 'foo' [CreateBy], '2016-10-24 09:29:18.548'[CreateDate], 'foo'[UpdateBy], '2016-10-24 09:29:18.548'[UpdateDate], 'E'[MT], 185761[MID], 3[BGID]
union
select 54372, 'foo', '2016-10-24 09:30:18.548', 'foo', '2016-10-24 09:30:18.548', 'E', 185761, 2
Run Code Online (Sandbox Code Playgroud)
和目标表
select 54379 Id, 'foo' [CreateBy], '2016-10-24 09:29:18.548'[CreateDate], 'foo'[UpdateBy], '2016-10-24 10:29:18.548'[UpdateDate], 'E'[MT], 185761[MID], 3[BGID]
Run Code Online (Sandbox Code Playgroud)
我想要的是基于MT,MID和
当我使用SQL Merge语句时,我收到错误
MERGE语句尝试多次更新或删除同一行.当目标行与多个源行匹配时会发生这种情况.MERGE语句不能多次更新/删除目标表的同一行.优化ON子句以确保目标行最多匹配一个源行,或使用GROUP BY子句对源行进行分组
我的合并是这样的
MERGE
FooBar AS target
USING
(
SELECT
E.[Id],
E.[CreateBy],
E.[CreateDate],
E.[UpdateBy],
E.[UpdateDate],
E.[MT],
E.[MID],
E.[BGID]
FROM @FooBar E
) AS source
ON
source.MID = target.MID
AND source.MT = target.MT
WHEN MATCHED …Run Code Online (Sandbox Code Playgroud)