我想知道如何确定控件何时可以访问用户,何时不是?
让我说我正在编写一个自定义控件,它扩展了一个TextBox
,我想知道什么时候可见,在可见变化触发的处理程序中做一些自定义逻辑.
怎么办?如何判断控件是否对用户可见?扩展a的自定义控件TextBox
可以在Button
例如内部并且Button
可以接收,Visibility.Collapsed
因此它的所有内部嵌套控件都将是invisibe,这就是我想知道的.如何设置是否可见,无论Visibility属性的值是什么?
我听说这会刷新 UI,但为什么呢?Dispatcher
调用这个空操作,那就是没有调用InvalidateMeasure()
会触发 UI 在操作内重新测量、重新排列和重新渲染。update/refresh
UI的度量和安排过程在哪里?
private static Action EmptyDelegate = delegate() { };
public static void Refresh(UIElement uiElement)
{
uiElement.Dispatcher.Invoke(DispatcherPriority.Render, EmptyDelegate);
}
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
EDITED:
我想知道为什么渲染 UI 的细节。像这样well that triggers ui update
的答案对我没有帮助。
我坚持ThemeInfo
我的里面的属性AssemblyInfo.cs
文件.我正在尝试编写自定义控件.自定义控件位于名为"MyCustomControls.dll"的dll中.此外,控件本身来自另一个自定义控件,该控件位于另一个名为"MyAnotherCustomControls.dll"的dll中.
我在MSDN上读到,必须使用2个参数声明ThemeInfo,这些参数负责控制主题特定位置和通用特定位置,但我不知道什么是"主题"和什么是"通用".我怎么能更好地理解这两个?
如果有人能从头开始向我解释什么是"通用"和什么是"主题".此外何时使用"通用"或"主题".WPF系统如何使用这两个系统?我真的需要用简单的英语解释,所以如果您要发布MSDN链接,请节省您的时间.我阅读了有关ThemeInfo的msdn文档,但我得不到它.
还有人可以告诉我如何使用ThemeInfo
告诉我的"MyCustomControls.dll"来使用"MyAnotherCustomControls.dll"中定义的字典资源吗?这甚至可以通过ThemeInfo来做,还是我必须处理"MyCustomControls.dll"中的MergedDirectories?我希望WPF系统负责定位资源,以便我可以使用"MyAnotherCustomControls.dll"中的样式键,而无需在"MyCustomControls.dll"中添加合并目录.
我正在使用OneWayToSource
绑定,似乎它始终将我的source属性设置为null.为什么会这样?它给我带来了麻烦,因为我需要源属性中的target属性的值而不是null.
这是我的代码:
MyViewModel.cs:
public class MyViewModel
{
private string str;
public string Txt
{
get { return this.str; }
set { this.str = value; }
}
}
Run Code Online (Sandbox Code Playgroud)
MainWindow.cs:
public MainWindow()
{
InitializeComponent();
MyViewModel vm = new MyViewModel();
vm.Txt = "123";
this.DataContext = vm;
}
Run Code Online (Sandbox Code Playgroud)
MainWindow.xaml:
<Window x:Class="OneWayToSourceTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525"
xmlns:local="clr-namespace:OneWayToSourceTest">
<Grid>
<local:MyButton Content="{Binding Path=Txt, Mode=OneWayToSource}"/>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
MyButton.cs:
public class MyButton : Button
{
public MyButton()
{
this.Content = "765";
}
}
Run Code Online (Sandbox Code Playgroud)
目标属性是MyButton.Content
.源属性是 …
我在C#中使用Actions,我想知道在希望GC正确收集对象后是否需要将Action的实例设置为null?这是一个例子:
public class A
{
public Action a;
}
public class B
{
public string str;
}
public class C
{
public void DoSomething()
{
A aClass = new A();
B bClass = new B();
aClass.a = () => { bClass.str = "Hello"; }
}
}
Run Code Online (Sandbox Code Playgroud)
在我的Main方法中我有这样的东西:
public void Main(...)
{
C cClass = new C();
cClass.DoSomething();
Console.WriteLine("At this point I dont need object A or B anymore so I would like the GC to collect them automatically.");
Console.WriteLine("Therefore I …
Run Code Online (Sandbox Code Playgroud) 我想知道什么是更快.
list.Clear() or list = new List<..>()???
Run Code Online (Sandbox Code Playgroud)
哪一个留下了美好的记忆足迹?
引擎盖下会发生什么?
我知道这两个命令执行两个不同的事情,因为第一个清除列表但不破坏实例,第二个释放旧实例但初始化新实例虽然最终结果是相同的,那就是摆脱项目.