以下面的窗口布局为例:Grid
定义了一个元素。它有 3 行。每一行都有一个 Button 元素。如何获取RowDefinition
它所属的 Button的对象?谢谢。
注意:通过调用Grid.GetRow(Button element)
,我获得了Grid.Row
该 Button 元素的属性。我不需要那个——而是我需要实际的RowDefinition
对象。
我想创建一个迭代键控集合的方法.我想确保我的方法支持任何扩展的集合的迭代KeyedCollection<string, Collection<string>>
这是方法:
public void IterateCollection(KeyedCollection<string, Collection<string>> items)
{
foreach (??? item in items)
{
Console.WriteLine("Key: " + item.Key);
Console.WriteLine("Value: " + item.Value);
}
}
Run Code Online (Sandbox Code Playgroud)
它显然不起作用,因为我不知道哪种类型应该替换循环中的问号.我不能简单地放object
或var
因为我需要稍后在循环体中调用Key
和Value
属性.我在寻找什么类型的?谢谢.
我有一个MainWindow.xaml文件:
<Window.Resources>
<CollectionViewSource x:Key="cvs"
Source="{Binding Source={StaticResource ResourceKey=DetailsCollection}}" />
<CollectionViewSource x:Key="DetailScopes">
<CollectionViewSource.Source>
<ObjectDataProvider
MethodName="GetValues"
ObjectType="{x:Type system:Enum}">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="entities:DetailScope" />
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</CollectionViewSource.Source>
</CollectionViewSource>
<DataTemplate x:Key="AccountDetail"
DataType="{x:Type entities:AccountDetail}">
<DockPanel>
<ComboBox
DockPanel.Dock="Left"
ItemsSource="{Binding Source={StaticResource ResourceKey=DetailScopes}}"
SelectedItem="{Binding Path=Scope}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Converter={StaticResource DetailScopeConverter}}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBox Text="{Binding Path=Value}" />
</DockPanel>
</DataTemplate>
</Window.Resources>
...
<ListBox
ItemTemplate="{StaticResource ResourceKey=AccountDetail}"
ItemsSource="{Binding Source={StaticResource ResourceKey=cvs}}" />
Run Code Online (Sandbox Code Playgroud)
和它的代码隐藏类,我在其中为详细信息范围定义了过滤器:
public class MainWindow
{
public MainWindow()
{
CollectionViewSource detailScopes;
InitializeComponent();
// Attach filter to the collection view source
detailScopes …
Run Code Online (Sandbox Code Playgroud) 我定义了一个静态资源:
<UserControl x:Class="MyProject.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Width="255"
Height="300">
<UserControl.Resources>
<sys:Double x:Key="CornerRadiusValue">5</sys:Double>
</UserControl.Resources>
...
Run Code Online (Sandbox Code Playgroud)
稍后在 XAML 文件中,我尝试在为边框设置左上角半径时使用该值:
<Border
Width="40"
Height="30"
BorderThickness="1,1,0,0"
BorderBrush="Red">
<Border.CornerRadius>
<CornerRadius TopLeft="{StaticResource CornerRadiusValue}" />
</Border.CornerRadius>
</Border>
Run Code Online (Sandbox Code Playgroud)
在设计时,一切正常,更改CornerRadiusValue
静态资源的值会更改边框上的角半径。但是,当我想运行它时,我收到一条XamlParseException
消息异常:
无法设置只读属性“System.Windows.CornerRadius.TopLeft”。
我究竟做错了什么?我如何使它工作?谢谢。
这是SQL表:
KEY | NAME | VALUE
---------------------
13b | Jeffrey | 23.5
F48 | Jonas | 18.2
2G8 | Debby | 21.1
Run Code Online (Sandbox Code Playgroud)
现在,如果我输入:
SELECT *
FROM table
WHERE VALUE = 23.5
Run Code Online (Sandbox Code Playgroud)
我会得到第一排.
我需要完成的是获得下面的第一行和下两行.有办法吗?
列没有排序,WHERE条件不参与行的选择,第一个除外.我只需要在返回的行之下添加两行 - 在SELECT查询返回的行之后输入的行.
wpf ×2
c# ×1
collections ×1
cornerradius ×1
data-binding ×1
grid ×1
silverlight ×1
sql ×1
uielement ×1
xaml ×1