我在silverlight中很新,我的应用程序遇到了一些问题。我将应用程序日期保存在数据库和IsolatedStorage中。
我在UI顶部有一个Image控件,用户可以随时查看应用程序的当前日期。我正在使用图像,因为我创建了一些时尚的图像来表示mm.yyyy格式的日期。
我在主页Authentication_LoggedIn()中设置了图像控件的URI:
//setez luna curenta in isolatedStorage
adminUtilizContext.GetSetariParticulare(4, 0, (op) =>
{
foreach (var item in op.Value)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("lunaCurenta"))
IsolatedStorageSettings.ApplicationSettings["lunaCurenta"] = item.Substring(2);
else
IsolatedStorageSettings.ApplicationSettings.Add("lunaCurenta", item.Substring(2));
Uri uri;
uri = new Uri("/Indeco.SIEF;component/Images/Calendar/"+item.Substring(2)+".png", UriKind.RelativeOrAbsolute);
dataLuna.Source = new BitmapImage(uri);
}
}, null);
xaml看起来像这样:
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
<Image Name="dataLuna" HorizontalAlignment="Right"/>
</StackPanel>
它工作正常,但当用户更改当前日期时会出现问题。在数据库和IsolatedStorage中正确存储。我正在更改图像源,但在手动刷新页面之前,新图像不会出现。
请您告诉我如何自动执行此操作而无需手动刷新页面!
最好的问候。
用户更改日期的代码位于相应UI(CurrentConfigurations.xaml)的ViewModel(CurrentConfigurationViewModel.cs)中。有一个带有月份的组合框,SelectedItemChanged会自动更新数据库和IsolatedStorage。这就是我所在的位置我把你在上一次评论中看到的代码放了一遍。今年也有一个NumericUpDown控件也是如此。但是现在让我们来谈谈这个月,之后我会自己做这一年:D!
再次感谢
正如你在这张图片中看到的那样,当用户登录申请日期是2011年4月(右上)并且在我修改月份之后,stil显示旧日期并且我在Db中验证了,在隔离存储中它似乎没问题。你可以看到我写的代码来更新图像源。
答案 0 :(得分:2)
您可以尝试设置保存图像的Property,然后将Image Source绑定到此属性。您的类需要实现INotifyPropertyChanged接口,然后您可以通知Image控件您的属性已更改,它将重新加载图像。 我希望这有帮助。 :)
如果这是您的代码,那么您将生成一个全新的MainPage并设置它的dataLuna ImageSource,而不是原始页面dataLuna控件。
我很高兴我可以帮忙。
答案 1 :(得分:1)
我的建议是从日期更改发生的页面/控件中触发事件。在主页面中,您可以订阅该事件并重新加载图像。希望这会有所帮助。
答案 2 :(得分:0)
大家好,再次感谢您的兴趣!我已经解决了我的问题:
var mp = ((Application.Current.RootVisual as ContentControl).Content as UserControl).Content as Indeco.SIEF.MainPage;
Debug.Assert(mp != null);
Uri uri;
uri = new Uri("/Indeco.SIEF;component/Images/Calendar/" + id.ToString() + ".png", UriKind.RelativeOrAbsolute);
mp.dataLuna.Source = new BitmapImage(uri);