『壹』 wpf中,如何引用其他xaml文件中的Resources
假设指定的 xaml 是一个 Window 对象,则比较简回单的做法是答
<Window.Resources>
<SolidColorBrushx:Key="myBrush"Color="Blue"/>
<Stylex:Key="myStyle"TargetType="{x:TypeButton}">
<SetterProperty="Background"Value="Red"/>
</Style>
</Window.Resources>
varwin=newWindow1();
varbrush=win.TryFindResource("myBrush")asBrush;
varstyle=win.Resources["myStyle"]asStyle;
『贰』 如何在wpf中实现文件夹选择功能
System.Windows.Forms.FolderBrowserDialogfbd=newSystem.Windows.Forms.FolderBrowserDialog();
System.Windows.Interop.HwndSourcesource=PresentationSource.FromVisual(this)asSystem.Windows.Interop.HwndSource;
System.Windows.Forms.IWin32Windowwin=newWinFormWindow(source.Handle);
System.Windows.Forms.DialogResultresult=fbd.ShowDialog(win);
if(result.Equals(System.Windows.Forms.DialogResult.OK))
{
MessageBox.Show(fbd.SelectedPath);
}
//其中w类的代码如下(你可以自己命名成自己喜欢的类名):
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Text;
namespaceMyClasses
{
publicclassWinFormWindow:System.Windows.Forms.IWin32Window
{
IntPtr_handle;
publicWinFormWindow(IntPtrhandle)
{
_handle=handle;
}
#regionIWin32WindowMembers
IntPtrSystem.Windows.Forms.IWin32Window.Handle
{
get{return_handle;}
}
#endregion
}
}
『叁』 visual studio里如何引用同一个文件夹里的类
假设Student 如下定义
namespace ABC.CED
{
public class Student
{
}
}
窗体类里
private void method1()
{
ABC.CED.Student s = new ABC.CED.Student();
}
『肆』 wpf中,UserControl对象如何调用window类下的某个文本框
usercontrol本身是自定义的东西,怎么可能会获取到MyWindow里的东西,除非你自己写方法,然后mywindow在使用usercontrol的时候给你写的方法传递你需要让usercontrol接受的东西。