我有一个列表框,显示TFS查询的结果.我想在后面的代码中更改ListBoxItem的样式,以获得查询结果中包含的列.
ListBoxItem的样式在我的Windows.Resoruces部分中定义.我试过这个:
public T GetQueryResultsElement<T>(string name) where T : DependencyObject
{
ListBoxItem myListBoxItem =
(ListBoxItem)(lstQueryResults.ItemContainerGenerator.ContainerFromIndex(0));
// Getting the ContentPresenter of myListBoxItem
ContentPresenter myContentPresenter =
myListBoxItem.Template.LoadContent().FindVisualChild<ContentPresenter>();
// Finding textBlock from the DataTemplate that is set on that ContentPresenter
DataTemplate myDataTemplate = myContentPresenter.ContentTemplate; <------+
T myControl = (T)myDataTemplate.FindName(name, myContentPresenter); |
|
return (T)myControl; |
} |
|
ContentTemplate is null ----------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
但ContentTemplate为null.我从这里获得了代码,然后使用LoadContent调用对其进行了修改(原始代码为ContentPresenter提供了null).
无论如何.如果你知道改变代码中现有样式的方法,我很乐意看到它.
如果你需要它们的细节:
我将在我的ListBoxItem样式中使用WrapPanel.这就是我想要添加额外的TextBlock项目.
这是我风格的一部分:
<!--Checkbox ListBox-->
<Style x:Key="CheckBoxListStyle" TargetType="ListBox">
<Style.Resources>
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Tag" Value="{Binding …Run Code Online (Sandbox Code Playgroud) 我正在使用MVVM模式编写WPF应用程序.我不需要为我的用户控件提供代码隐藏文件.优雅地删除这些文件的最佳方法是什么?
我可以创建一个用户控件类,然后我可以将这个类用于我的所有视图.(更多信息:http://sondreb.com/blog/post/No-Code-Behind-for-MVVM.aspx)
还有其他方法吗?
谢谢.
基本上我正在尝试这样做:
Path path = new Path( );
string sData = "M 250,40 L200,20 L200,60 Z";
var converter = TypeDescriptor.GetConverter( typeof( Geometry ) );
path.Data = ( Geometry )converter.ConvertFrom( sData );
Run Code Online (Sandbox Code Playgroud)
但它不会编译,Silverlight似乎没有TypeDescriptor类...
在开发时,我喜欢尝试理解的不仅仅是"只是这样做".特别是对于WPF,我喜欢从GUI(xaml)和代码隐藏中理解绑定的两个方面.话虽这么说,我想知道以下代码的等价物.
我有一个带有一些预定义的"ICommand"实例的ViewModel,例如添加,编辑,保存,取消,退出等等 - 它们按预期工作.现在,看看有一个按钮的View(Window)的绑定,我将它绑定到命令,类似于.
<Button Command="{Binding ExitCommand}" Content="Exit" ... />
Run Code Online (Sandbox Code Playgroud)
这恰当地完成了我希望允许表单退出(并做我正在玩的其他任何事情).
代码隐藏的后果是什么样的.我知道对于属性,例如IsEnabled或IsVisible绑定到依赖对象/属性,但是我不理解绑定到命令执行时的相关性.谢谢.
我正在使用javascript向客户端的JQGrid添加一些行数据:
var grid = jQuery("#<%= JQGridMembers.ClientID %>");
var rowKey = grid.getGridParam("selrow");
var newRow = [{ ID: memberId, FullName: memberFullName, Percent: parseInt(percent)}];
grid.addRowData(memberId, newRow);
Run Code Online (Sandbox Code Playgroud)
上面的代码运行良好,但如何在代码隐藏中获取所有插入的行数据(在JQGrid中)?
我在文件后面的代码中添加表。我想在其中添加标签。
<table id="tbl" runat="server">
<tr>
<th>test</th>
<td>
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我不知道如何通过代码添加。
那么谁能告诉我如何添加标签?
我得到了一个用 aspx/c# 编写的 web 项目。当我将它加载到 Visual Studio 2010 时,我收到很多错误,告诉我代码隐藏文件中的某些控件在当前上下文中不存在。
我检查了常见的陷阱,比如错误的代码隐藏文件名、缺少runat-attribute、重新启动 VS、重新加载项目,但没有解决错误。
我还能做些什么来检查问题出在哪里?
我有个问题.当我从代码后面添加一个事件处理程序到一个按钮时,事件永远不会被触发.但是当我在创建按钮标签时添加它时,它完美地工作,我从后面的代码创建按钮,然后将其添加到表中.
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="show table" OnClick="Button1_OnClick" />
<table border="1">
<thead>
<tr>
</tr>
</thead>
<tbody id="tbody" runat="server">
</tbody>
</table>
</div>
</form>
protected void Button1_OnClick(object sender, EventArgs e)
{
var row = new TableRow();
var btnDownload = new Button { ID = "ID", Text = "Click Here" };
btnDownload.Click += ClickEvent;
var cell = new TableCell();
cell.Controls.Add(btnDownload);
row.Controls.Add(cell);
tbody.Controls.Add(row);
}
protected void ClickEvent(object sender, EventArgs e)
{
Debug.WriteLine(((Button)sender).Text);
}
Run Code Online (Sandbox Code Playgroud) 我已经在应用程序开发的中途放弃了 MVVM,只是为了推出这个应用程序。
我在后面的代码中编写了一个方法来更新数据库/数据网格等。
我的应用程序导航正在使用命令到 ViewModel 来触发一些事件,但除了一次初始化类之外,从不触及代码隐藏。
所以基本上我按下按钮一次,它使用默认的初始设置,但是一旦视图被初始化,我就不能再调用我的代码隐藏 Update() 方法。
如何从视图模型调用此代码隐藏方法?
谢谢!!
更新代码
//Navigation ViewModel
//PaneVm.cs
public CommandExtension NewAssignmentCommand { get; set; }
private void CreateCommands()
{
NewAssignmentCommand = new CommandExtension(NewAssignment, CanNewAssignment);
}
GlobalCommands.NewAssignmentCommand = NewAssignmentCommand;
private bool CanNewGroupAssignment(object obj)
{
return true;
}
private void NewGroupAssignment(object obj)
{
OnPropertyChanged("NewGroupAssignmentCommand");
}
//MainVM.cs
// [Events]
void _PaneVm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == "NewGroupAssignmentCommand")
WorkspaceVm.CurrentVm = new NewAssignmentsVm();
}
//NewAssignmentVm.cs
//Constructor
public NewAssignmentsVm()
{
var rc = new RepositoryContext();
_RoResearchers = …Run Code Online (Sandbox Code Playgroud) 我有一个WPF应用程序,其中包含一些主要使用代码编写的旧版面板.我需要为面板上的控件设置AutomationProperties.AutomationId.例如,这个Checkbox
CheckBox myCheckbox = new CheckBox();
Run Code Online (Sandbox Code Playgroud)
如何设置AutomationProperties.AutomationId?
code-behind ×10
c# ×5
wpf ×5
asp.net ×4
button ×1
buttonclick ×1
events ×1
html-table ×1
jqgrid ×1
mvvm ×1
silverlight ×1
styles ×1
tablerow ×1
view ×1
viewmodel ×1