我有一个winform usercontrol,而不是我想添加到wpf项目.
我添加了相关的引用(WindowsFormsIntegration,SystemWindowsForms和我的用户控件dll)并在我的XAML中添加了这一行:
xmlns:MyControl="clr-namespace:xx.xx.xx;assembly=xx.xx"
Run Code Online (Sandbox Code Playgroud)
然后这个:
<WindowsFormsHost><MyControl:control></MyControl:control></WindowsFormsHost>
Run Code Online (Sandbox Code Playgroud)
当我写"MyControl:"时,"控件"是自动显示的,这意味着VS识别控件并且所有引用都添加正确...但是当我编译项目时,这给了我标题中的错误.
编辑
当我编译所有项目时我非常奇怪我有错误"类型或名称空间名称"xx'找不到..."但我添加了所有引用并且VS识别命名空间以便编译器为什么不要找不到它们?如果这个问题得到解决我相信其他问题也会消失.
我尝试做这样的事情:
<DataGrid Name="myGrid" ItemSource="{Binding Path=MyCollection}">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem
Command="{Binding RemoveRow}"
CommandParameter="{Binding ElementName=myGrid, Path=SelectedItem}">
</ContextMenu>
</DataGridContextMenu>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
但我总是得到null(我也试过SelectedIndex和SelectedValue)
如果我将以下参数传递给执行代码,它的工作原理如下:
<MenuItem Command="{Binding RemoveRow}" CommandParameter="1">
Run Code Online (Sandbox Code Playgroud) 我写了这段代码并得到了一个例外:
Background属性不指向路径'(0)中的dependencyobject.(1)'
我在论坛的其他帖子中看到了这个问题,但没有找到解决方案.
<WrapPanel.Style>
<Style>
<Style.Triggers>
<Trigger Property "WrapPanel.Visibility" Value="Visible">
<Trigger.EnterActions>
<BeginStoryboard HandoffBehavior="Compose">
<Storyboard RepeatBehavior="Forever" AutoReverse="True">
<ColorAnimation
Storyboard.TargetProperty="(WrapPanel.Background).(SolidColorBrush.Color)"
Duration="00:00:01" To="Red"/>
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
</Trigger>
</Style.Triggers>
</Style>
</WrapPanel.Style>
Run Code Online (Sandbox Code Playgroud)
对此有何帮助?
我看到了这个例子--Binding.UpdateSourceTrigger属性
在示例中,UpdateSourceTrigger设置为Explicit,然后在视图代码中调用TextBox名称的UpdateSource.
但是,如果我使用MVVM dp,我不想让我的控件和源属性在VM中,而不是在视图中,那么将控件绑定到VM属性并将UpdateSourceTrigger设置为显式的正确方法是什么?
我想这样做,因为在我的情况下它的ShowDialog窗口,我希望只有当用户点击"确定"时源才会更新
提前致谢!
我知道使用lock(this)或任何共享对象是错误的.
我想知道这种用法是否合适?
public class A
{
private readonly object locker = new object();
private List<int> myList;
public A()
{
myList = new List<int>()
}
private void MethodeA()
{
lock(locker)
{
myList.Add(10);
}
}
public void MethodeB()
{
CallToMethodInOtherClass(myList);
}
}
public class OtherClass
{
private readonly object locker = new object();
public CallToMethodInOtherClass(List<int> list)
{
lock(locker)
{
int i = list.Count;
}
}
}
Run Code Online (Sandbox Code Playgroud)
这个线程安全吗?在OtherClass我们锁定私有对象,所以如果class A锁具有其私有锁,列表仍然可以在锁定块中更改OtherClass?
我有以下方法
void DoSome(){
if (int.Parse(SomeStringProperty) > 8)
// do something
if (int.Parse(SomeStringProperty) < 10)
// do something
}
Run Code Online (Sandbox Code Playgroud)
JIT是否知道保留解析的值,或者更好地执行以下操作:
void DoSome(){
var x = int.Parse(SomeStringProperty);
if (x > 8)
// do something
if (x < 10)
// do something
}
Run Code Online (Sandbox Code Playgroud)
我可以在这里看到两个优化:
我的问题只是关于一个需要保持一致的优化,而不是关于可以依赖于很多因素的2优化.
总之,当我编写C#app时,上面的例子中哪些更受欢迎?
更新
如果答案不是,为什么它与此不同:
foreach (var x in MyMethod.GetEnumeration())
Run Code Online (Sandbox Code Playgroud)
这里没有必要这样做:
var lst = MyMethod.GetEnumeration();
foreach (var x in lst)
Run Code Online (Sandbox Code Playgroud)