我正在尝试淡入我的应用程序的"app"区域的新控件,该区域在删除现有控件后以编程方式添加.我的代码看起来像这样:
void settingsButton_Clicked(object sender, EventArgs e)
{
ContentCanvas.Children.Clear();
// Fade in settings panel
NameScope.SetNameScope(this, new NameScope());
SettingsPane s = new SettingsPane();
s.Name = "settingsPane";
this.RegisterName(s.Name, s);
this.Resources.Add(s.Name, s);
Storyboard sb = new Storyboard();
DoubleAnimation settingsFade = new DoubleAnimation();
settingsFade.From = 0;
settingsFade.To = 1;
settingsFade.Duration = new Duration(TimeSpan.FromSeconds(0.33));
settingsFade.RepeatBehavior = new RepeatBehavior(1);
Storyboard.SetTargetName(settingsFade, s.Name);
Storyboard.SetTargetProperty(settingsFade, new PropertyPath(UserControl.OpacityProperty));
ContentCanvas.Children.Add(s);
sb.Children.Add(settingsFade);
sb.Begin();
}
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,我收到错误"没有适用的名称范围来解析名称'settingsPane'."
我可能做错了什么?我很确定我已经正确注册了一切:(
我有一个课,我在一个PropertyGrid
.我发现通过设置CategoryAttribute
每个属性,它显然为每个项目创建了一个新类别.这将我的属性网格设置为每个项目都有一个[+],其中包含我的自定义名称,这不是我想要实现的行为.
在Visual Studio中,如果单击解决方案资源管理器中的项目(例如,程序集),它将具有零树节点和仅有完美命名属性的列表,即任何字符串都可以标识属性,而不仅仅是对象的名称.所以不要这样:
[+文件路径]
FilePath | propertyValue
[+ File Size]
FileSize | 0 KB
我在找这个:
[+文件]
文件路径| 值
文件大小| 0 KB
甚至上面没有初始的[+]节点.我已经通过System.ComponentModel命名空间寻找适用的属性,但我找不到.
我怎样才能达到这个效果?它必须是可能的,Visual Studio会这样做,我相信它们是相同的组件,而不是派生和扩展的组件.
我正在尝试设置我的WPF应用程序,以便在未处理异常时弹出错误对话框.在好的'WinForms中,这可以通过添加来实现
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Run Code Online (Sandbox Code Playgroud)
到您的Program.cs文件,然后在事件处理代码中显示您想要的任何对话框.在WPF中,我试过使用
app.Dispatcher.UnhandledException += new System.Windows.Threading.DispatcherUnhandledExceptionEventHandler(Dispatcher_UnhandledException);
Run Code Online (Sandbox Code Playgroud)
但是,当我在错误处理自定义窗口上使用Show()时,应用程序立即转到"blahblah.exe已停止工作......"并关闭.如果我使用ShowDialog(),窗口可以使用,直到它关闭,然后相同的"...已停止工作......"对话框弹出并死亡.
在WinForms中,似乎关闭任何错误对话框将允许应用程序继续运行,具体取决于异常的严重程度.我似乎无法弄清楚如何在WPF中正确地做到这一点.
有任何想法吗?
在过去一小时左右的时间里,我一直在为这个问题撕掉我的头发.
我有一些代码如下:
videoTile.Icon = new ImageSourceConverter().ConvertFrom(coDrivr4.Properties.Resources.Music.GetHbitmap()) as ImageSource;
Run Code Online (Sandbox Code Playgroud)
当我运行我的代码时,它表示发生了NullReferenceException."音乐"和GetHbitmap()的返回都不为空.
我试图通过属性获取图像,因为这是我弄清楚如何访问我的Resources文件夹中的图像的唯一方法.我只是将它们作为资源添加到app.xaml文件中,但由于某些原因我没有使用app.xaml文件.
我试错了吗?我需要做的就是获取我的资源目录中的图像的ImageSource对象.我可以在我的XAML中使用它们,但不能在我的生活中使用任何代码.
PS:我不能只将它们作为资源添加到XAML文件中,因为这只是一个类,所以没有XAML文件.
我有一个继承自的集合类List<>
.我已经设置了一个函数来按照某个属性对列表进行排序,如下所示:
public PlaylistCollection SortByName(IEnumerable<Playlist> playlists)
{
return (PlaylistCollection)playlists.OrderBy(p => p.Name);
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在我的代码中使用排序结果时,如下所示:
artistSource.Playlists = (PlaylistCollection)new List<Playlist>(artistSource.Playlists.SortByName(artistSource.Playlists));
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Unable to cast object of type 'System.Linq.OrderedEnumerable`2[...Playlist,System.String]'
to type '...PlaylistCollection'."
Run Code Online (Sandbox Code Playgroud)
考虑到VS告诉我存在明确的转换,这是令人沮丧的,所以我添加了上面的演员.
我如何正确地投射IEnumerable<>
到我的收藏中?
我的应用程序需要驱动器上的地图,因为在操作期间将无法访问互联网.我已经决定使用MapPoint 2009了,但地图'风格'与我的整体UI外观完全冲突.
我想知道是否有一些方法可以在地图上自定义绘制所有内容(道路,标签等)?在我看来,也许MapPoint应用程序本身有一些主题,但我现在没有它的方便:(
我完全更喜欢WPF方法,但实际上,此时的任何事情都有帮助:)
我创建了一个UserControl,它本质上是一个按钮.它上面有一个Image和一个Label,我创建了两个属性来设置Image的源和Label的文本,如下所示:
public ImageSource Icon
{
get { return (ImageSource)this.GetValue(IconProperty); }
set { this.SetValue(IconProperty, value); icon.Source = value; }
}
public static readonly DependencyProperty IconProperty = DependencyProperty.Register("Icon", typeof(ImageSource), typeof(NavigationButton));
public string Text
{
get { return (string)this.GetValue(TextProperty); }
set { this.SetValue(TextProperty, value); label.Content = value; }
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(NavigationButton));
Run Code Online (Sandbox Code Playgroud)
但是,当我将控件添加到我的页面时,控件不会响应我在XAML中设置的任何属性,例如<controls:MusicButton Icon="/SuCo;component/Resources/settings.png/>
什么都不做.
我究竟做错了什么?
我有一个椭圆,只是一个圆圈.我的问题是我想从较大圆圈的中间切出一个圆形孔,似乎没什么用.我尝试了不透明面具,但那些都没有用.
为了使事情更复杂,大圆圈有一个DropShadowEffect.但由于圆圈略微透明,你可以看到它后面有一个大阴影圆圈.这不是模型的样子,我想知道是否有办法让阴影只出现在圆的边缘,无论圆圈是多么透明.
谢谢!
c# ×6
wpf ×6
animation ×1
bitmapeffect ×1
casting ×1
dependencies ×1
exception ×1
generics ×1
linq ×1
mappoint ×1
properties ×1
propertygrid ×1
resources ×1
storyboard ×1
winforms ×1
xaml ×1