基本上,我如何在静态类中创建自己的一组颜色,或者这样我可以这样做:
什么存在:
<Setter ... Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
Run Code Online (Sandbox Code Playgroud)
我想要的:
<Setter ... Value="{DynamicResource {x:Static MyColors.Color1}}"/>
Run Code Online (Sandbox Code Playgroud) 基本上,我不知道从哪里开始:
我有我的Shell.xaml窗口.我也有我的Popup.xaml窗口.
我设置Shell.xaml以导入PopupWindow然后当PopupWindow Loaded事件触发时,它会:
Popup.Owner = this;
Popup.Show();
Run Code Online (Sandbox Code Playgroud)
现在,我需要能够让PopupWindow的ViewModel与Shell.xaml进行通信.基本上,我需要能够让PopupWindow告诉用户输入的Shell的ViewModel信息.
为了保持这种分离,我不想将客户端的viewmodel的任何实例传递给弹出窗口,我更倾向于让Popup的ViewModel以某种方式与客户端的ViewModel进行通信而不知道它实际上是在与谁通话.
基本上,我有一个自定义控件FooControl。
public class FooControl : ItemsControl
{
//Code
}
Run Code Online (Sandbox Code Playgroud)
我需要添加一些事件处理,但我更喜欢使用 Commanding,而不是使用 RoutedEvent。但我不太确定如何去做这件事。如果我想要它,那么当 Bar1Property (DependencyProperty) 更改时,它会引发 Execute 关联的执行属性。我通过 .NET Reflector 查看了 ButtonBase 代码,哇,这看起来太复杂了。添加命令这么复杂吗?显然,我还必须做到这一点,以便我的控件根据 CanExecuteChanged 是否更改来启用/禁用其自身的某些部分。但我想那是另一部分。
这是到目前为止我的 OnBar1Changed 函数......
private static void OnBar1Changed(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
FooControl element = (FooControl)obj;
//What to do here?
}
Run Code Online (Sandbox Code Playgroud) <DataTemplate x:Key="MyTemplate" DataType="{x:Type l:MyViewModel}">
<l:MyView />
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
有没有什么办法可以用我的一类价值取代"MyTemplate"?
public sealed class MyTemplateSelector : DataTemplateSelector
{
public const string TemplateName = "MyTemplate";
//I use the TemplateName const to retrieve the correct DataTemplate
}
Run Code Online (Sandbox Code Playgroud) 基本上,我希望我的UserControl能够接受一种ItemsControl类型,以便我的XAML看起来像这样:
<my:MyControl DataContext="{Binding InnerViewModel}">
<ItemsControl ... />
</my:MyControl>
Run Code Online (Sandbox Code Playgroud)
这样,MyControl会显示自定义Items控件以及其他控件吗?
我不知道该怎么做.我有一个批处理脚本文件,我用来做多个msbuild调用.我不希望msbuild输出污染我的命令窗口,而是希望它转储到日志文件中.我不知道该怎么做,但到目前为止这是我的脚本:
@ECHO Building shared libraries ...
msbuild "SharedLibraries.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:: Copy dll files to specific location
@ECHO Building primary application...
msbuild "Myapp.sln"
:: Not sure how to catch an unsuccessful build here for my GOTO ERROR?
:ERROR
Run Code Online (Sandbox Code Playgroud)
那么,我该怎么做:
基本上,如果我有:
<TextBlock Text="{Binding MyValue, Converter={StaticResource TransformedTextConverter},
ConverterParameter=?}" />
Run Code Online (Sandbox Code Playgroud)
你将如何传递某种类型的项目作为ConverterParameter.我想我可以传入某种类型的分隔列表,但我不确定要使用哪种类型的分隔符,或者是否有内置方法传递参数数组?
基本上,我想将所有XAML资源保存在外部程序集中(对于我的样式).我在我的应用程序中引用了这个外部程序集.
有没有关于附属程序集或诸如此类的内容或如何访问这些样式,以便我的应用程序仍然可以具有StaticResource标记而没有编译错误?
如果我有一个字符串数组,例如:var array = new[] { "the", "cat", "in", "the", "hat" },我想加入它们,每个单词之间有一个空格我可以简单地调用String.Join(" ", array).
但是,假设我有一个整数数组数组(就像我可以有一个字符数组数组).我想将它们组合成一个大型数组(展平它们),但同时在每个数组之间插入一个值.
var arrays = new[] { new[] { 1, 2, 3 }, new[] { 4, 5, 6 }, new { 7, 8, 9 }};
var result = SomeJoin(0, arrays); // result = { 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9 }
Run Code Online (Sandbox Code Playgroud)
我写了一些东西,但它非常难看,我确信有更好,更清洁的方式.也许效率更高?
var result = new int[arrays.Sum(a => a.Length) + arrays.Length - 1];
int offset = 0;
foreach (var …Run Code Online (Sandbox Code Playgroud) 基本上,我有一个FooControl(我并没有设置高度/宽度明确)加入Grid。
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<FooControl x:Name="HWFoo" Content="HelloWorld" Grid.Row="0">
<FooControl.RenderTransform>
<TransformGroup>
<RotateTransform Angle="270" />
<TranslateTransform Y="{Binding ActualWidth, ElementName=HWFoo}" />
</TransformGroup>
</FooControl.RenderTransform>
</FooControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
但是,现在的问题是 FooControl 填满了整行,当它被转换时,它看起来很奇怪(因为它的高度/宽度)。
wpf ×8
c# ×5
xaml ×3
resources ×2
arrays ×1
batch-file ×1
colors ×1
command ×1
data-binding ×1
icommand ×1
itemscontrol ×1
key ×1
linq ×1
mef ×1
msbuild ×1
mvvm ×1
performance ×1
prism ×1
styles ×1
window ×1