我有wpf TreeView - 绑定到一些数据.Treeview位于窗口的左侧,该窗口分为两个区域,其中树是导航,右侧的面板根据所选的树节点更改内容.
并非树视图的所有节点都生成详细信息.我想禁用这些节点的选择.任何的想法?
谢谢
我通过反射循环对象中的所有属性:
For Each p As PropertyInfo In values.[GetType]().GetProperties()
If p.CanRead Then
'Do stuff
End If
Next
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我如何确定有问题的属性是否是通用列表(Of T)?如果是,我需要循环列表本身.
我已经尝试过GetType和TypeOf,但还没有设法让任何工作.
谢谢.
****更新和澄清**
为了澄清,我想保持这种通用性.我不想指定T的类型,我需要循环列表项并在每个项上调用ToString方法.T可以是许多不同类型之一(特定于应用程序的引用类型).是否可以在不指定类型的情况下执行此操作?
(VB.NET 2005 with .Net 2.0)
我有这个代码来静音/取消静音主音量
private const int APPCOMMAND_VOLUME_MUTE = 0x80000;
private const int WM_APPCOMMAND = 0x319;
[DllImport("user32.dll")]
public static extern IntPtr SendMessageW(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
SendMessageW(this.Handle, WM_APPCOMMAND, this.Handle, (IntPtr)APPCOMMAND_VOLUME_MUTE);
Run Code Online (Sandbox Code Playgroud)
我想知道如何获得主音量/ precent,因为我想知道声音是否已经静音.
编辑:或者我想分开静音/取消静音,这样我就有两个功能 - 一个用于静音,另一个用于静音.
谢谢
我有一个WPF应用程序,其中有一个列表框中填充了"匹配"类型的项目.如何使按钮(包含在项目中)实际选择项目以便我可以提取值?
这是我的代码:既不起作用,因为单击按钮实际上并不选择该项目
private void LayButton_Click(object sender, RoutedEventArgs e)
{
var x = (Market)ListBoxSelectedMarket.SelectedItem;
var y = (sender as ListBoxItem);
}
Run Code Online (Sandbox Code Playgroud)
谢谢
嗨我有问题绑定方法对"LabelLink"控件的点击事件.我使用pseudeo LabelLink控件,我想大家都知道这个解决方案有textBox和超链接.
这是我的代码:
<TextBlock Margin="10,12,10,4">
<Hyperlink Name="RegLink"
NavigateUri="http://registracia.azet.sk/"
Micro:Message.Attach="[Event Click]=[Action OpenDefaultBrowser(NavigateUri)]"
FontSize="12">Registrácia</Hyperlink>
Run Code Online (Sandbox Code Playgroud)
问题是我只能在框架元素上绑定方法.
我得到这个编译错误:
Cannot attach type "ActionMessage" to type "Hyperlink". Instances of type "ActionMessage" can only be attached to objects of type "FrameworkElement".
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索,芽没有找到任何合适的解决方案.
谢谢你的建议.
我尝试使用textBlock或Label控件制作一个假的linkLabel但它们没有click事件处理程序.
我有一个场景,我需要指定函数
void SomeFunction(int value)
Run Code Online (Sandbox Code Playgroud)
为此,我用了两个DataGrid.
DataGrid是函数DataGrid包含所选函数的参数我只希望在DataGrid函数中选择有效函数时启用参数DataGrid.如果NewItemPlaceHolder (CanUserAddRows="True"DataGrid选择a 时的最后一行)或选择为空,我希望它被禁用.我尝试使用DataTrigger,但我无法使用它
<Style TargetType="DataGrid">
<Setter Property="IsEnabled" Value="False"/>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=functionDataGrid,
Path=SelectedItem}"
Value="{x:Type systemData:DataRowView}">
<Setter Property="IsEnabled" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
Run Code Online (Sandbox Code Playgroud)
是否可以检查Binding产生的值是否具体Type?否则,有没有人有任何其他解决方案?截至目前,我正在处理这个SelectedCellsChanged事件,但我不想使用代码
谢谢
如何MarkupExtension从代码中设置自定义?
您可以轻松地从Xaml设置.这同样适用于Binding和DynamicResource.
<TextBox FontSize="{Binding MyFontSize}"
Style="{DynamicResource MyStyle}"
Text="{markup:CustomMarkup}"/>
Run Code Online (Sandbox Code Playgroud)
通过代码设置相同的值需要一些不同的方法
绑定:使用textBox.SetBinding或BindingOperations.SetBinding
Binding binding = new Binding("MyFontSize");
BindingOperations.SetBinding(textBox, TextBox.FontSizeProperty, binding);
Run Code Online (Sandbox Code Playgroud)DynamicResource:使用SetResourceReference
textBox.SetResourceReference(TextBox.StyleProperty, "MyStyle");
Run Code Online (Sandbox Code Playgroud)CustomMarkup:如何MarkupExtension从代码中设置自定义?如果我打电话给ProvideValue那个案子,我怎么得到一个IServiceProvider?*
CustomMarkupExtension customExtension = new CustomMarkupExtension();
textBox.Text = customExtension.ProvideValue(??);
Run Code Online (Sandbox Code Playgroud)我在这个问题上发现了很少,所以可以做到吗?
HB回答了这个问题.只是在这里添加一些细节,为什么我想这样做.我试图为以下问题创建一个解决方法.
问题是,由于密封,您无法从中获取Binding和覆盖ProvideValue.您将不得不这样做:自定义WPF绑定标记扩展的基类.但问题是,当你返回a Binding时Setter你得到一个异常,但在Style它之外它工作正常.
我已经在几个地方读过你应该返回它MarkupExtension自己,如果它TargetObject是一个Setter允许它一旦它被应用到一个实际的reeavaluate这是FrameworkElement有道理的.
但是,只有在TargetProperty类型有效时才有效object,否则异常返回.如果您查看源代码,BindingBase …
public XML()
{
this.InitializeComponent();
XmlDocument document_name = new XmlDocument();
XmlElement student = document_name.CreateElement("Student");
XmlElement name = document_name.CreateElement("Chandru");
student.AppendChild(name);
document_name.AppendChild(student);
XmlAttribute id = document_name.CreateAttribute("ID");
name.SetAttributeNode(id);
id.Value = "sst5038";
XmlElement fname = document_name.CreateElement("FName");
fname.InnerText = "Anjappn";
name.AppendChild(fname);
XmlElement mname = document_name.CreateElement("MName");
mname.InnerText = "Thaiyamuthu";
name.AppendChild(mname);
document_name.AppendChild(student);
document_name.Save(@"D:\student.xml");
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码.我在wpf中创建一个xml文件作为代码,我将此文件保存在我的本地磁盘D:\ student.xml中
document_name.Save(@"D:\student.xml");
Run Code Online (Sandbox Code Playgroud)
但是我想将这个xml文件(student.xml)保存在我正在使用的项目文件中.
我该怎么做呢
请帮我...
我想在WPF中为我的Listbox提供一个上下文菜单.我使用整个列表框的上下文菜单来完成它,但即使您没有单击某个项目,也可以通过richt-click来获取上下文菜单.
我在谷歌找到了一些东西,但这没有用.
我试过这样的事情:
<ListBox Margin="5" ItemsSource="{Binding}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}">
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding Name}" Click="MenuItemName_Click"/>
<MenuItem Header="{Binding Capital}" Click="MenuItemCapital_Click"/>
<MenuItem Header="{Binding Population}" Click="MenuItemPopulation_Click"/>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
我尝试使用像示例中的文本块,与其他教程中的其他元素一样,我厌倦了没有和许多其他东西 - 但没有任何效果.我的列表框项目没有上下文菜单:(
后来我尝试过这样的事:
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<ListBoxItem.ContextMenu>
<ContextMenu>
<MenuItem/>
</ContextMenu>
</ListBoxItem.ContextMenu>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
但它也没有用.
有人可以给我一个提示/工作示例:)?
谢谢
我正在玩WPF Binding和变量.显然,只能绑定DependencyProperties.我提出了以下内容,它完全正常:代码隐藏文件:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public string Test
{
get { return (string)this.GetValue(TestProperty); }
set { this.SetValue(TestProperty, value); }
//set { this.SetValue(TestProperty, "BBB"); }
}
public static readonly DependencyProperty TestProperty = DependencyProperty.Register(
"Test", typeof(string), typeof(MainWindow), new PropertyMetadata("CCC"));
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(Test);
Test = "AAA";
MessageBox.Show(Test);
}
}
Run Code Online (Sandbox Code Playgroud)
XAML:
<Window x:Class="WpfApplication3.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase"
Title="MainWindow" Height="350" Width="525"
DataContext="{Binding RelativeSource={RelativeSource Self}}">
<Grid>
<TextBox Height="31" HorizontalAlignment="Left" Margin="84,86,0,0" Name="textBox1" VerticalAlignment="Top" Width="152" …Run Code Online (Sandbox Code Playgroud) wpf ×8
c# ×6
xaml ×4
listbox ×2
listboxitem ×2
.net ×1
binding ×1
button ×1
click ×1
contextmenu ×1
datagrid ×1
generics ×1
hyperlink ×1
markup ×1
reflection ×1
treeview ×1
treeviewitem ×1
triggers ×1
vb.net ×1