我在c#中有一些代码行,Resharper这样缩进:
Console.WriteLine("Hello");
this.MySuperFunction(
argument1,
argument2,
argument3
);
Console.WriteLine("World");
Run Code Online (Sandbox Code Playgroud)
由于我的个人编码风格,我希望上面的内容与右括号(或括号)一起出现,没有任何缩进,如下所示:
Console.WriteLine("Hello");
this.MySuperFunction(
argument1,
argument2,
argument3
);
Console.WriteLine("World");
Run Code Online (Sandbox Code Playgroud)
我尝试使用Resharper上的各种选项,但找不到任何选项.有没有办法让这项工作成功?
我在WPF中创建一个应用程序,它使用鼠标滚轮放大/缩小图像.缩放量基于鼠标滚轮的转动量.
问题是Delta值始终为120,如MSDN中所述.因此,即使我将车轮转1档或5档,它也总是120.你知道解决这个问题吗?
从ResourceDictionary中定义的DataTemplate内部引用StaticResources时,我遇到了一些奇怪的行为.
在这个例子中,我使用ResourceDictionary中定义的DataTemplate填充数字1到9的列表框.
这是MainWindow.xaml代码:
<Window x:Class="testResources.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525"
Height="350">
<Grid>
<ListBox Width="100" ItemTemplate="{StaticResource NumberTemplate}">
<ListBox.ItemsSource>
<Int32Collection>1,2,3,4,5,6,7,8,9</Int32Collection>
</ListBox.ItemsSource>
</ListBox>
</Grid>
Run Code Online (Sandbox Code Playgroud)
它NumberTemplate在ResourceDictionary1.xaml中定义:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="NumberTemplate">
<Grid Background="{StaticResource CoolNumbersColor}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="35" />
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Background="{StaticResource CoolNumbersColor}" Text="{Binding Mode=OneWay}" />
</Grid>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
StaticResource CoolNumbersColor在App.xaml中定义ResourceDictionary1.xaml.这是我的App.xaml文件:
<Application x:Class="testResources.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="CoolNumbersColor">GreenYellow</SolidColorBrush>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/ResourceDictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
首先,我可以在Visual Studio 2010设计器中看到预期的行为.确实会出现一个彩色的数字列表.但是在尝试运行此示例时,我收到错误
"找不到名为'CoolNumbersColor'的资源.资源名称区分大小写"
我不明白为什么会这样.CoolNumbersColor评估是否以某种方式推迟?从词汇上讲,它位于合并的resourcedictionary之前.
使这项工作的唯一方法(除了使用DynamicResources)是创建第二个ResourceDictionary(例如ResourceDictionary2.xaml),CoolNumbersColor在那里定义并将它们全部合并为ResourceDictionary.MergedDictionaries:
<Application x:Class="testResources.App" …Run Code Online (Sandbox Code Playgroud) 我在一个类中有这个代码:
private static MyObject _locker = new MyObject();
...
lock (_locker)
{
...
_locker = new MyObject();
...
}
Run Code Online (Sandbox Code Playgroud)
它会锁定_locker吗?
我试图基于其中每种颜色已经被分配有值的调色板(例如红色= 0,深绿色= 10,绿色= 20,浅绿= 30)和一个用户选择的值来画WPF控件的背景(例如,25),该会产生颜色.我希望得到的颜色是2个最接近的颜色值之间的插值(例如,对于值25,它应该给出Green和LightGreen之间的颜色)
为此,我正在考虑在WPF中使用现有的LinearGradientBrush; 设置GradientStops,偏移量并将颜色设置为指定值.有没有办法做到这一点,还是应该实现自己的颜色插值功能?
谢谢.