我理解为什么GUI控件具有线程亲和力.
但是为什么控件不在内部使用它们的方法和属性中的调用?
现在你必须做这样的事情只是为了更新TextBox价值:
this.Invoke(new MethodInvoker(delegate()
{
textBox.Text = "newValue";
}
Run Code Online (Sandbox Code Playgroud)
虽然使用就textBox.Text = "newValue";足以代表相同的逻辑.
所有必须做的就是改变textBox.Text逻辑(伪代码):
public string Text
{
set
{
if(!this.InvokeRequired)
// do the change logic
else
throw new BadThreadException();
}
}
Run Code Online (Sandbox Code Playgroud)
对此:
public string Text
{
set
{
if(!this.InvokeRequired)
// do the change logic
else
this.Invoke(new MethodInvoker(delegate()
{
// do the change logic
}
}
}
Run Code Online (Sandbox Code Playgroud)
吸气剂和方法也是如此.
我当然不打算删除Invoke/BeginInvoke,我只是问为什么控件不会自己进行必要的线程切换而不是抛出异常.
在WPF中管理大量图像(10,000+)的最佳方法是什么?这是针对类似于此的2d平铺地图编辑器:http://www.mapeditor.org/.
目前我有一个画布,其中所有图块都是图像,列表框包含可供选择的不同图像.每个图块都作为子图形添加到画布中,然后存储在列表中以供以后访问.通过将tile的Source属性设置为在列表框中选择的属性,可以在画布中绘制.它适用于大约50x50瓦片地图,但是上面的任何内容都会导致加载延迟,通常是慢速应用.
有什么建议吗?QT可能更适合而不是wpf吗?
提前致谢
如何在Opera中完成这项工作?我为Opera找到了这段代码,但它对我不起作用:
function AddToFavorites(title, url) {
if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
return false;
}
else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title);
return false;
}
else if(window.opera && window.print) { // Opera Hotlist
var elem = document.createElement('a');
elem.setAttribute('href',url);
elem.setAttribute('title',title);
elem.setAttribute('rel','sidebar');
elem.click();
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
Dragonfly错误控制台是静默的,没有发生错误.
我有没有理由(或者应该)不将依赖属性声明为非静态?
我需要创建一个具有双向可绑定属性的接口.INotifyPropertyChanged在接收端看起来有点麻烦,因为它依赖于字符串标识符.
我有四个级别的数据结构定义如下:
Dictionary<Type1, Dictionary<Type2, Dictionary<Type3, List<Type4>>>>
Run Code Online (Sandbox Code Playgroud)
整个事情被封装在一个同样保持线程安全的类中.目前它只是在读取/操作数据时锁定整个集合(读取比写入更常见).
我正在考虑更换Dictionarywith ConcurrentDictionary和Listwith ConcurrentBag(它的项目不必订购).
如果我这样做,我可以消除锁定并确保并发集合能够正常工作吗?
我在用户控件中有一个文本框我试图从我的主应用程序更新但是当我设置textbox.Text属性时它不显示新值(即使textbos.Text包含正确的数据).我试图将我的文本框绑定到属性以解决这个问题,但我不知道如何,这是我的代码 -
MainWindow.xaml.cs
outputPanel.Text = outputText;
Run Code Online (Sandbox Code Playgroud)
OutputPanel.xaml
<TextBox x:Name="textbox"
AcceptsReturn="True"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Text="{Binding <!--?????--> }"/> <!-- I want to bind this to the Text Propert in OutputPanel.xmal.cs -->
Run Code Online (Sandbox Code Playgroud)
OutputPanel.xaml.cs
namespace Controls
{
public partial class OutputPanel : UserControl
{
private string text;
public TextBox Textbox
{
get {return textbox;}
}
public string Text
{
get { return text; }
set { text = value; }
}
public OutputPanel()
{
InitializeComponent();
Text = "test";
textbox.Text = Text;
}
}
Run Code Online (Sandbox Code Playgroud)
}
data-binding wpf user-controls dependency-properties properties
我正在使用 WPF 并使用带有复选框列的 DataGrid。问题是我希望复选框拉伸并填充单元格

这是我的 XAML:
<Grid>
<Controls:DataGrid ItemsSource="{Binding Persons}" AutoGenerateColumns="False">
<Controls:DataGrid.Columns>
<Controls:DataGridTextColumn Binding="{Binding Name}"/>
<Controls:DataGridTemplateColumn>
<Controls:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox />
</DataTemplate>
</Controls:DataGridTemplateColumn.CellTemplate>
</Controls:DataGridTemplateColumn>
</Controls:DataGrid.Columns>
</Controls:DataGrid>
</Grid>
Run Code Online (Sandbox Code Playgroud) 我有一个像这样声明的表列:
file_id number(10) generated always as identity primary key,
Run Code Online (Sandbox Code Playgroud)
是否有可能以编程方式从其后备序列中获取currval/ nextval不实际查看SYS.表获取序列的名称,然后使用execute immediate该名称?
我刚刚将第一个转换器从int转换为string.我有一个带有整数的组合框填充(年),但如果值为0,我希望组合框显示"全部".
这是我的转换器:
public class IntToString : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null)
{
int intY = (int)value;
if (intY == 0)
{
String strY = "All";
return strY;
}
else
{
return intY.ToString();
}
}
return String.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
}
}
Run Code Online (Sandbox Code Playgroud)
在XAML中,我应该在哪里设置转换器?我在组合框的ItemsSource中尝试过:
ItemsSource="{Binding YearsCollection, Converter={StaticResource intToStringYearConverter}}"
Run Code Online (Sandbox Code Playgroud)
但我总是InvalidcastException这样做:
int intY = (int)value;
Run Code Online (Sandbox Code Playgroud) 我想迭代特定 INamedTypeSymbol 的参数,并在这些类型参数本身是通用的情况下递归到它们中。但是我不能这样做,因为类型参数作为 ITypeParameterSymbol 返回,而泛型参数仅在 INamedTypeSymbol 上可用。
如何为 ITypeParameterSymbol 的实例找到 INamedTypeSymbol?
wpf ×6
c# ×4
.net ×2
concurrency ×2
xaml ×2
.net-4.0 ×1
2d ×1
converter ×1
data-binding ×1
datagrid ×1
javascript ×1
map ×1
opera ×1
oracle ×1
oracle12c ×1
plsql ×1
properties ×1
roslyn ×1
tile ×1
winforms ×1