我有一个WPF窗口,我通过调用从另一个窗口创建Show(),然后让它Close()自己.当窗口关闭时,我希望它会死掉,调用它的析构函数,并删除它的所有子元素(比如计时器......).
调用此类操作的正确方法是什么?
是否有win32函数在创建窗口后更改窗口的样式?我想更改指定的样式标志CreateWindowEx.具体来说,我想将标准窗口转换为没有边框且没有调整大小的窗口.
我正在WinXP上编写一个WPF应用程序,我用这样的vista主题覆盖了默认主题:
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var themerd = new ResourceDictionary();
themerd.Source = new Uri(@"PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component\themes/aero.normalcolor.xaml", UriKind.Relative);
Resources.MergedDictionaries.Add(themerd);
}
Run Code Online (Sandbox Code Playgroud)
它主要工作得很好.当我使用按钮等控件时:
<Button />
Run Code Online (Sandbox Code Playgroud)
样式看起来很好,但如果我使用具有不同样式的Button,如下所示:
<Button>
<Button.Style>
<Style TargetType="Button">
<Setter Property="Width" Value="80" />
</Style>
</Button.Style>
</Button>
Run Code Online (Sandbox Code Playgroud)
该样式将使用标准的WinXP样式覆盖指定的主题样式,而不是在其上构建.这对我来说是非常有限的.有没有办法避免这个问题?
我创建了自己的附属属性,如下所示:
public static class LabelExtension
{
public static bool GetSelectable(DependencyObject obj)
{
return (bool)obj.GetValue(SelectableProperty);
}
public static void SetSelectable(DependencyObject obj, bool value)
{
obj.SetValue(SelectableProperty, value);
}
// Using a DependencyProperty as the backing store for Selectable. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SelectableProperty =
DependencyProperty.RegisterAttached("Selectable", typeof(bool), typeof(Label), new UIPropertyMetadata(false));
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用依赖于它的触发器创建一个样式:
<!--Label-->
<Style TargetType="{x:Type Label}">
<Style.Triggers>
<Trigger Property="Util:LabelExtension.Selectable" Value="True">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Label}">
<TextBox IsReadOnly="True" Text="{TemplateBinding Content}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style> …Run Code Online (Sandbox Code Playgroud) 我需要使用Visual Studio T4(模板)创建一些文件.将一些配置设置导入多个.tt文件并在模板代码部分中访问它的最佳方法是什么.
我通过COM Interop和WebBrowser WPF控件将我的JavaScript代码中的一些数据返回到我的C#代码.我已成功返回Javascript中的数据:
var result = new Array();
result[0] = cbCamera.selectedItem;
result[1] = cbMicrophone.selectedItem;
Run Code Online (Sandbox Code Playgroud)
现在我将对象结果放在C#中,如下所示:
result.GetType();
{Name = "__ComObject" FullName = "System.__ComObject"}
Run Code Online (Sandbox Code Playgroud)
如何获取此ComObject中此数组中包含的javascript字符串?
我想尝试一下 VS2k10,但我处于 VS2k8 环境中。我比较了 VS2k10 中升级后的项目文件,唯一的区别是更新后的版本号 - 如何阻止 VS 这样做?
我的WPF应用程序以大约4kb/s的速度泄漏内存.任务管理器中的内存使用量不断攀升,直到应用程序崩溃并出现"内存不足"异常.
通过我自己的研究,我发现这里讨论的问题是:在WPF和#8中追踪内存泄漏:http://blogs.msdn.com/jgoldb/archive/2008/02/04/finding-memory-泄漏功能于WPF的基于applications.aspx
描述的问题是: 这是在框架版本中存在的WPF泄漏,包括.NET 3.5 SP1.这是因为WPF选择使用哪个HWND将消息从呈现线程发送到UI线程.此示例销毁创建的第一个HWND并在新窗口中启动动画.这会导致从渲染线程发送的消息堆积而不进行处理,从而有效地泄漏内存.
提供的解决方案是: 解决方法是在App类构造函数中首先创建一个新的HwndSource.这必须在WPF创建任何其他HWND之前创建.只需创建这个HwndSource,WPF就会使用它来从渲染线程向UI线程发送消息.这样可以确保处理所有消息,并且不会泄漏任何消息.
但我不明白解决方案! 我有一个我正在使用的Application的子类,我尝试在该构造函数中创建一个窗口但是没有解决问题.
按照字面意思给出的说明,看起来我只需要将它添加到我的Application构造函数中:
new HwndSource(new HwndSourceParameters("MyApplication"));
Run Code Online (Sandbox Code Playgroud) wpf ×4
c# ×2
com ×1
com-interop ×1
hwnd ×1
javascript ×1
memory-leaks ×1
t4 ×1
winapi ×1
window ×1
windows-xp ×1
xaml ×1