大家都是SO观众.我通常是Android开发人员,但现在我正在开发针对WPF和Android的跨平台应用程序.话虽如此,几乎没有关于如何直接做我想要的信息.因此,我最终找到了一个由3部分组成的博客系列,深入探讨了如何开发基于Windows的跨平台MVVM项目.只要我将PCL设置为与Xamarin.Android兼容,任何不会抛出错误的代码应该在我进入Android方面时起作用.以下是博客文章的链接:博客1,博客2,博客3.我再做Android,所以我不熟悉为WPF应用程序编写代码.
所以今天我的问题只涉及与上述链接博客文章相关的PCL-WPF方面.我尽可能地遵循帖子中的每一步.该博客使用WinRT和WinPhone作为两个目标平台,所以我不得不尝试自己搞清楚,以便在WPF上运行.我必须做的两件事是使用IsolatedStorage并基本上使用WinPhone App.Xaml来构建WPF.
我已经完成了博客一直到最后并构建成功.我甚至可以在第三篇博文的末尾看到我的示例调试行.但是,当我去运行它时,我得到以下内容:
ActivationException未被用户代码处理
GalaSoft.MvvmLight.Extras.dll中出现"Microsoft.Practices.ServiceLocation.ActivationException"类型的异常,但未在用户代码中处理
$ exception {Microsoft.Practices.ServiceLocation.ActivationException:在缓存中找不到类型:StackOverF.Services.IStorageService.在GalaSoft.MvvmLight.Ioc.SimpleIoc.DoGetService(键入serviceType,String key,Boolean cache)中的c:\ MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras(PCL)\ Ioc\SimpleIoc.cs:第537行at GalaSoft.MvvmLight.Iv.SimpleIoc.GetService(类型serviceType)位于c:\ MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras(PCL)\ Ioc\SimpleIoc.cs:第789行,位于GalaSoft.MvvmLight.Ioc.SimpleIoc .MakeInstanceTClass在c:\ MvvmLight\Source\GalaSoft.MvvmLight\GalaSoft.MvvmLight.Extras(PCL)\ Ioc\SimpleIoc.cs:line 729} System.Exception {Microsoft.Practices.ServiceLocation.ActivationException}
你们有什么可以告诉我的,也许博客作者可能会跳过我需要做的事情吗?也许如果在这块"巨石"上扔出足够的岩石,它就会开裂......
我的Visual Studio解决方案目前基本上只有两个项目.一个是可移植类库.另一个是WPF应用程序.在不久的将来,一旦我开始在WPF方面工作,我将使用Xamarin中的PCL来重用Android项目中的代码.但是,Android方面不是我的问题的一部分.我只处理WPF项目时遇到了上述问题.
IMainViewModel.cs
using GalaSoft.MvvmLight.Command;
using StackOverF.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StackOverF.ViewModels {
public interface IMainViewModel {
ObservableCollection<Workload> Workload { get; }
RelayCommand RefreshCommand { get; }
RelayCommand AddCommand { get; }
} …Run Code Online (Sandbox Code Playgroud) 基本上,我的问题归结为SQLite-Net扩展(NuGet链接)是否与Frank A. Krueger的SQLite-net PCL兼容。据我了解,在某个时候,Oystein Krog创建了一个分叉来改进过去的功能(可能在Frank更新之前?),因此SQLite.Net PCL诞生了。
既然有PCLFrank 的“官方” 版本,我想坚持使用它而不是fork。但是,目前尚不清楚是否SQLite-Net Extensions仅支持fork。该网站表示支持,SQLite-net但相关性却说SQLite.net。为我(和将来的人们)的缘故所做的任何澄清将不胜感激!!!
编辑:我知道“ SQLite-Net PCL”只是NuGet包的名称,实际上不是独立的PCL。我有这个(没有SQLite-Net扩展),可以在我实际的PCL中的代码中完全工作。
数据绑定到ObservableCollection,我正在ItemsControl用Buttons。我正在UniformGrid用来帮助均匀分布对象,无论对象中有5个还是5000个对象ObservableCollection。
需求:用户搜索/过滤之后ObservableCollection,我想更新商品的IsVisible属性以显示/隐藏它们...同时还要巩固空间。
原理:我认为,从性能角度考虑,更新属性要比执行Clear()and循环将过滤后的项目重新添加回databound 更好ObservableCollection。
问题:尽管当前的实现(下面的代码)确实隐藏了按钮,但无论Visibility我尝试使用哪个属性,它们仍然占据着空间。
免责声明:我不仅仅只是简单地“修复”当前代码。例如,如果一个可行的解决方案没有使用UniformGrid例如,但仍然取得了可持续的结果,那么我可能可以使用它!ViewModel侧面也是如此。
<ItemsControl Name="ItemsList"
Width="Auto"
HorizontalContentAlignment="Left"
ItemsSource="{Binding ItemsVM.WorkList}"
ScrollViewer.CanContentScroll="True" VirtualizingStackPanel.IsVirtualizing="true"
VirtualizingStackPanel.VirtualizationMode="Standard"
>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="5" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Width="250" Height="50"
FontSize="18" FontWeight="Bold"
Background="{Binding TextColor, Converter={StaticResource TextToColorConvert}, UpdateSourceTrigger=PropertyChanged}"
Margin="1,1,1,1" HorizontalAlignment="Center" VerticalAlignment="Center"
BorderBrush="WhiteSmoke" BorderThickness="0" Click="workNumSelect"
Content="{Binding Workload.WorkNum}"
Cursor="Hand" Opacity=".8"
Visibility="{Binding IsVisible, Converter={StaticResource BoolToCollapsedVisConvert}, UpdateSourceTrigger=PropertyChanged}"
/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl"> …Run Code Online (Sandbox Code Playgroud)