我是WPF的新手.我有两个窗口,例如window1和window2.我在window1中有一个按钮.如果我单击该按钮,则必须打开window2.我该怎么办?
这是我试过的代码:
window2.show();
Run Code Online (Sandbox Code Playgroud) <Grid x:Name="LayoutRoot">
<ComboBox x:Name="com_ColorItems" Height="41" Margin="198,114,264,0" VerticalAlignment="Top" FontSize="13.333" FontWeight="Bold" Foreground="#FF3F7E24"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)
使用上面的代码我将组合框绿色中的所有项目着色.
private void Window_Loaded(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 5; i++)
{
com_ColorItems.Items.Add(i);
}
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,我已经将五个项目填充到组合框中.现在我喜欢动态地将代码中的第3项(3)的颜色更改为"红色".我怎样才能做到这一点?
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="MPS.Window1"
x:Name="Window"
Title="Window1"
Width="640" Height="480">
<Window.Resources>
<ControlTemplate x:Key="bs" TargetType="{x:Type xctk:ButtonSpinner}">
<Grid SnapsToDevicePixels="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Border x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2"/>
<ContentPresenter Content="{TemplateBinding Content}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Grid Grid.Column="1" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.Visibility>
<TemplateBinding Property="ShowButtonSpinner">
<TemplateBinding.Converter>
<BooleanToVisibilityConverter/>
</TemplateBinding.Converter>
</TemplateBinding>
</Grid.Visibility>
<RepeatButton x:Name="PART_IncreaseButton" IsTabStop="{TemplateBinding IsTabStop}" Style="{DynamicResource Xceed.Wpf.Toolkit.Themes.StaticResourceKey}">
<RepeatButton.ContentTemplate>
<DataTemplate>
<Path Data="M0,3C0,3 0,4 0,4 0,4 3,4 3,4 3,4 3,3 3,3 …Run Code Online (Sandbox Code Playgroud) 我试图在特定字段中检查给定值是否包含.这里是我写的代码
bool _Contains = LabelDetails.Name.Contains("1");
Run Code Online (Sandbox Code Playgroud)
现在想要检查cantains方法中的多个值.我尝试如下,但显示异常(" 方法'包含'没有重载需要3个参数 ");
bool _Contains = LabelDetails.Name.Contains("1","2","3");
Run Code Online (Sandbox Code Playgroud) int cell = 1;
foreach (var item in resourceDictionary.Keys)
{
excelSheet.Cells[cell, 1] = item;
excelSheet.Cells[cell, 2] = resourceDictionary[item];
cell++;
}
Run Code Online (Sandbox Code Playgroud)
在c#中使用linq有没有最简单的方法来实现这个目的?