Tag: silverlight

在样式列表框ItemContainer上指定datacontext类型

在ListBox我使用语法将ItemContainer的IsSelected属性绑定到我的ViewModel的IsSelected属性。 它工作正常,但我得到一个Resharper警告: 无法在“FooSolution.BarViewModel”类型的数据上下文中解析属性“IsSelected”。 如何在ListBox ItemContainer上指定指定DataContext类型以消除此警告? 这是代码。 我有一个BarViewModel类: public ObservableCollection FooItems { get;set; } BarViewModel被分配给Control中包含ListBox的DataContext 和FooViewModel如下: public bool IsSelected { get { return isSelected; } set { if (isSelected == value) { return; } isSelected = value; RaisePropertyChanged(() => IsSelected); } } 和XAML这样: 更新我尝试使用setC设置d:DataContext ,正如HighCore所建议的那样,但不幸的是,它没有帮助,甚至打破了构建: (抛出:错误1标签’DesignInstance’在XML命名空间’schemas.microsoft.com/expression/blend/2008’中不存在;;第31行位置50.) 更新2最后,解决方案是在样式元素本身上设置d:DataContext (请参阅下面的答案):

从URL到流的图像

我从url获取图片: BitmapImage image = new BitmapImage(new Uri(article.ImageURL)); NLBI.Thumbnail.Source = image; 这很完美,现在我需要把它放在一个流中,使其成为字节数组。 我这样做: WriteableBitmap wb = new WriteableBitmap(image); MemoryStream ms = new MemoryStream(); wb.SaveJpeg(ms, image.PixelWidth, image.PixelHeight, 0, 100); byte[] imageBytes = ms.ToArray(); 并且代码因NullReference而失败,如何解决?

如何通过Reflection获取属性的DisplayAttribute?

我有一个像这样的Helper方法来获取PropertyName(试图避免魔术字符串) public static string GetPropertyName(Expression<Func> expression) { var body = (MemberExpression) expression.Body; return body.Member.Name; } 但有时我的PropertyNames也没有好好命名。 所以我想宁愿使用DisplayAttribute。 [Display(Name = “Last Name”)] public string Lastname {get; set;} 请注意我使用的是Silverlight 4.0。 我无法找到通常的命名空间DisplayAttributeName属性。 如何更改我的方法来读取eproperty的属性(如果可用)? 非常感谢,

如何将WriteableBitmap转换为BitmapImage?

BitmapImage bitmapImage = new BitmapImage(new Uri(“arka_projects_as_logo.png”, UriKind.Relative)); Image uiElement = new Image() { Source = bitmapImage }; ScaleTransform t = new ScaleTransform() { ScaleX = 0.2, ScaleY = 0.2 }; WriteableBitmap writeableBitmap = new WriteableBitmap(uiElement,t); 我想将此转换的结果(writeableBitmap)插入到System.Windows.Controls.Image中。 我这样做的时候: Image arkaImage = new Image() { Source = writeableBitmap }; arkaImage根本没有显示。 有什么办法可以让它发挥作用?

如何正确设置Silverlight CurrentUICulture / CurrentCulture?

我正在使用C#开发SL5应用程序,我希望将其国际化。 我发现以下内容来设置UI文化: var culture = new CultureInfo(Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName); Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; 像DatePicker这样的控件似乎可以选择它。 如果我使用’d’格式字符串格式化任何日期时间,我仍然会得到默认格式“M / dd / yyyy”。 SL究竟如何解释文化以及如何为整个应用程序正确设置? 谢谢 更新: 找到答案: 首先,在Application_Startup中设置适当的文化: var culture = new CultureInfo(“nl-BE”); Thread.CurrentThread.CurrentUICulture = culture; Thread.CurrentThread.CurrentCulture = culture; 然而,关键因素是添加以下内容以强制RootVisual的文化/语言: var root = RootVisual as Page; if (root != null) { root.Language = XmlLanguage.GetLanguage(Thread.CurrentThread.CurrentCulture.Name); }

UnauthorizedAccessException:Silverlight应用程序中的无线跨线程访问(XAML / C#)

相对较新的C#,并希望尝试使用它的一些第三方Web服务API。 这是XAML代码 这是C#代码 private void Button_Click(object sender, RoutedEventArgs e) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“http://api.twitter.com/1/users/show/keykoo.xml”); request.Method = “GET”; request.BeginGetResponse(new AsyncCallback(twitterCallback), request); } private void twitterCallback(IAsyncResult result) { HttpWebRequest request = (HttpWebRequest)result.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(result); TextReader reader = new StreamReader(response.GetResponseStream()); string strResponse = reader.ReadToEnd(); Console.WriteLine(“I am done here”); TwitterPost.Text = “hello there”; } 我猜这是因为回调在一个单独的线程上执行而不是UI? 在C#中处理这些类型的交互的正常流程是什么? 谢谢。

如何在silverlight中拖放“盒子”

我有一个像这样的盒子,现在我试图拖放盒子,用矩形和其他对象我做了,但有了这个我不知道该怎么办。 这是我如何做框的代码 XAML: c#代码: public partial class MyBox : UserControl { public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(“Header”, typeof(string), typeof(MyBox),null); public static readonly DependencyProperty TextProperty = DependencyProperty.Register(“Content”, typeof(string), typeof(MyBox),null); public string Header { get { return GetValue(HeaderProperty) as string; } set { SetValue(HeaderProperty, value); } } public string Text { get { return GetValue(TextProperty) as […]

在Windowsapp store的TextBlock和PasswordBox中垂直和水平居中文本

我试图将文本居中在TextBlock和PasswordBox中。 在TextBlock中,我使用TextAlignment属性水平居中文本,但它仍然靠近顶部。 如何垂直居中? 而在PasswordBox中没有与文本对齐关联的属性,如何实现这一点?

从Xaml绑定RichTextBox的文本

如何从xaml绑定RichTextArea的文本

Silverlight的Prism:如何在区域内以特定顺序维护视图

我正在为SL创建一种“导航面板”(实际上是一个ItemControl),并使用Regions允许每个模块将其链接添加到面板。 问题是模块加载不一致,因此面板中链接的顺序可以根据模块加载顺序而改变。 限制模块顺序是不可能的。 其他可行的选项是将区域的Views Collection绑定到ItemControl的顺序,问题是ViewCollection非常有限,因此对它进行排序非常困难。 我错过了一个选项吗,你有什么想法吗? 谢谢阿里尔