数据绑腚,绑TM的腚" #2
No files matched your search
@@ -69,7 +69,7 @@ namespace FileManager_UWP
|
||||
// 当导航堆栈尚未还原时,导航到第一页,
|
||||
// 并通过将所需信息作为导航参数传入来配置
|
||||
// 参数
|
||||
rootFrame.Navigate(typeof(TestLabelView), e.Arguments);
|
||||
rootFrame.Navigate(typeof(MainPage), e.Arguments);
|
||||
}
|
||||
// 确保当前窗口处于活动状态
|
||||
Window.Current.Activate();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace FileManager_UWP.Controls {
|
||||
private Canvas labelListCanvas;
|
||||
private bool _adding_new_label = false;
|
||||
private bool _hovering = false, _draging = false;
|
||||
|
||||
private int shit_cnt = 0;
|
||||
|
||||
private ResourceDictionary genericResourceDictionary;
|
||||
public LabelListControl() {
|
||||
@@ -39,8 +39,30 @@ namespace FileManager_UWP.Controls {
|
||||
var uri = new Uri("ms-appx:///Controls/LabelListControl.xaml");
|
||||
genericResourceDictionary = new ResourceDictionary();
|
||||
Application.LoadComponent(genericResourceDictionary, uri);
|
||||
AllowDrop = true;
|
||||
Loaded += LabelListControl_Loaded;
|
||||
//AllowDrop = true;
|
||||
//RegisterPropertyChangedCallback(ItemsControl.ItemsSourceProperty, this.tbTagChangedCallback);
|
||||
}
|
||||
|
||||
private void LabelListControl_Loaded(object sender, RoutedEventArgs e) {
|
||||
init();
|
||||
update();
|
||||
}
|
||||
|
||||
private void tbTagChangedCallback(DependencyObject sender, DependencyProperty dp) {
|
||||
if (dp == ItemsControl.ItemsSourceProperty) {
|
||||
// These lines produce the same result.
|
||||
Debug.WriteLine("The tag has been set to " + sender.ToString());
|
||||
Debug.WriteLine("The tag has been set to " + sender.GetValue(dp));
|
||||
ItemsSource = sender.GetValue(dp);
|
||||
shit_cnt++;
|
||||
if (shit_cnt >= 2) {
|
||||
init();
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 监听ItemSource改变
|
||||
/// </summary>
|
||||
@@ -298,23 +320,64 @@ namespace FileManager_UWP.Controls {
|
||||
/// 初始化控件
|
||||
/// </summary>
|
||||
private void init() {
|
||||
Debug.WriteLine("INIT LABEL LIST CONTROL");
|
||||
var itemsSource = ItemsSource as ObservableCollection<LabelItem>;
|
||||
if (ItemsSource != null && itemsSource == null) {
|
||||
ItemsSource = new ObservableCollection<LabelItem>(ItemsSource as IEnumerable<LabelItem>);
|
||||
itemsSource = ItemsSource as ObservableCollection<LabelItem>;
|
||||
}
|
||||
//var itemsSource = GetValue(ItemsControl.ItemsSourceProperty) as ObservableCollection<LabelItem>;
|
||||
itemsSource.CollectionChanged += ItemsSource_CollectionChanged;
|
||||
Button labelListButton = (Button)GetTemplateChild("LabelListPresenter");
|
||||
labelListButton.PointerEntered += LabelListCanvas_PointerEntered;
|
||||
labelListButton.PointerExited += LabelListCanvas_PointerExited;
|
||||
labelListCanvas = (Canvas)GetTemplateChild("LabelListCanvas");
|
||||
|
||||
//TextBlock textBlock = (TextBlock)GetTemplateChild("LabelTextBlock");
|
||||
//textBlock.Text = "测试自定义控件\nINIT";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 该Control被加载时调用
|
||||
/// </summary>
|
||||
protected override void OnApplyTemplate() {
|
||||
init();
|
||||
update();
|
||||
//shit_cnt++;
|
||||
//if (shit_cnt >= 2) {
|
||||
|
||||
//}
|
||||
}
|
||||
|
||||
//public new static readonly DependencyProperty ItemsSourceProperty = //Notice this is static. It's bound to an internal static hash table of some sort; I use to know exactly but forgot.
|
||||
//DependencyProperty.Register(
|
||||
// "ItemsSources",
|
||||
// /*The name of the property to register against.
|
||||
// * The static version is always the name of the property ended with Property
|
||||
// * i.e. SomeValue property is SomeValueProperty dependency property */
|
||||
// typeof(ObservableCollection<LabelItem>), //This is the type used to describe the property.
|
||||
// typeof(LabelListControl), //This is the type the dependency property relates to.
|
||||
|
||||
// /* Below this is the magic. It's where we supply the property meta data and can be delivered different ways.
|
||||
// * For this example I will supply only the default value and the event we want to use when the value is changed.
|
||||
// * Note:
|
||||
// * The event we supply is fired ONLY if the value is changed. This event is what we need to use to handle changes in the setter to cover binding operations as well. */
|
||||
// new PropertyMetadata(default(ObservableCollection<LabelItem>),
|
||||
// /* This is the default value the dependency property will have.
|
||||
// * It can be whatever you decide but make sure it works with the same type or you'll most likely get an error. */
|
||||
// /* This is the event fired when the value changes.
|
||||
// * Note: Dependency properties binding and events always operate on the UI thread. Cross threading will throw exceptions. */
|
||||
// new PropertyChangedCallback((s, e) => {
|
||||
// var ctr = s as LabelListControl; //The sender of the callback will always be of the type it's from.
|
||||
|
||||
// /* The values given from the e argument for OldValue and NewValue should be of type int in this example...
|
||||
// * but since we can't gaurantee the property is setup properly before here I always add a check. */
|
||||
// if (e.OldValue != e.NewValue) {
|
||||
// ctr.ItemsSource = e.NewValue;
|
||||
// }
|
||||
// //if (e.OldValue is int oldValue) { }
|
||||
// //if (e.NewValue is int newValue) {
|
||||
// // /* Now do what you want with the information. This is where you need to do custom work instead of using the setter.
|
||||
// // * Note: If you need to work on something in the MainPage remember this is a static event and you'll need to refer to the sender or s value in this case.
|
||||
// // * I've converted s to the variable mainPage for easy referencing here. */
|
||||
// // ctr.ItemsSource = newValue; //Note: The custom control should bind to this as well via XAML making this pointless. I set the value here just for educational purposes.
|
||||
// //}
|
||||
// })));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:FileManager_UWP.Controls">
|
||||
xmlns:local="using:FileManager_UWP.Controls"
|
||||
xmlns:model="using:FileManager_UWP.Model">
|
||||
|
||||
<Style TargetType="Button" x:Key="LabelButtonStyle">
|
||||
<Setter Property="Template">
|
||||
@@ -23,6 +24,14 @@
|
||||
</Style>
|
||||
|
||||
<Style TargetType="local:LabelListControl">
|
||||
<Setter Property="ItemsSource" Value="{Binding ItemsSource}"></Setter>
|
||||
<Setter Property="DataContext" Value="{Binding}"></Setter>
|
||||
|
||||
<!--<Setter Property="ItemTemplate">
|
||||
<Setter.Value>
|
||||
<DataTemplate x:DataType="model:LabelItem"></DataTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>-->
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="local:LabelListControl">
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace FileManager_UWP.Model {
|
||||
public abstract string Path { get; }
|
||||
public abstract Type Type { get; }
|
||||
public abstract BitmapImage Icon { get; }
|
||||
public abstract List<String> Labels { get; }
|
||||
public abstract List<LabelItem> Labels { get; }
|
||||
|
||||
public int CompareTo(object obj) {
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableDisk: Displayable {
|
||||
private readonly DriveInfo _drive;
|
||||
private readonly BitmapImage _icon = new BitmapImage();
|
||||
private readonly List<String> _labels = new List<String>();
|
||||
private readonly List<LabelItem> _labels = new List<LabelItem>();
|
||||
|
||||
private DisplayableDisk(DriveInfo d) {
|
||||
_drive = d;
|
||||
@@ -33,6 +33,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _drive.Name;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override Type Type => Type.Disk;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableFile: Displayable {
|
||||
private readonly StorageFile _file;
|
||||
private readonly BitmapImage _icon;
|
||||
private readonly List<String> _labels;
|
||||
private readonly List<LabelItem> _labels;
|
||||
|
||||
private DisplayableFile(StorageFile f) {
|
||||
_file = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<string> { "喵喵喵" };
|
||||
_labels = new List<LabelItem> { new LabelItem("喵喵喵") };
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFile> GetInstanceAsync(StorageFile f) {
|
||||
@@ -31,6 +31,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _file.Path;
|
||||
public override Type Type => Type.File;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -12,12 +12,12 @@ namespace FileManager_UWP.Model
|
||||
public class DisplayableFolder: Displayable {
|
||||
private readonly StorageFolder _folder;
|
||||
private readonly BitmapImage _icon;
|
||||
private readonly List<String> _labels;
|
||||
private readonly List<LabelItem> _labels;
|
||||
|
||||
private DisplayableFolder(StorageFolder f) {
|
||||
_folder = f;
|
||||
_icon = new BitmapImage();
|
||||
_labels = new List<string>();
|
||||
_labels = new List<LabelItem>();
|
||||
}
|
||||
|
||||
public static async Task<DisplayableFolder> GetInstanceAsync(StorageFolder f)
|
||||
@@ -49,6 +49,6 @@ namespace FileManager_UWP.Model
|
||||
public override string Path => _folder.Path;
|
||||
public override Type Type => Type.Folder;
|
||||
public override BitmapImage Icon => _icon;
|
||||
public override List<String> Labels => _labels;
|
||||
public override List<LabelItem> Labels => _labels;
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,12 @@ namespace FileManager_UWP.Model
|
||||
Path = path;
|
||||
Type = type;
|
||||
Icon = icon;
|
||||
Labels = new List<String>();
|
||||
Labels = new List<LabelItem>();
|
||||
}
|
||||
public override string Name { get; }
|
||||
public override string Path { get; }
|
||||
public override Type Type { get; }
|
||||
public override BitmapImage Icon { get; }
|
||||
public override List<String> Labels { get; }
|
||||
public override List<LabelItem> Labels { get; }
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
xmlns:Custom="using:Microsoft.Xaml.Interactivity"
|
||||
xmlns:Custom1="using:Microsoft.Xaml.Interactions.Core"
|
||||
xmlns:model="using:FileManager_UWP.Model"
|
||||
xmlns:controls="using:FileManager_UWP.Controls"
|
||||
x:Class="FileManager_UWP.View.FileListView"
|
||||
mc:Ignorable="d"
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
@@ -21,6 +22,9 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!--<controls:LabelListControl ItemsSource="{x:Bind vm.Labels}" />-->
|
||||
|
||||
|
||||
<Button
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
@@ -34,21 +38,21 @@
|
||||
Text="{Binding Path}"
|
||||
/>
|
||||
<ListView
|
||||
Name="MicroShitList"
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
Grid.ColumnSpan="2"
|
||||
ItemsSource="{Binding DisplayFileFolderItems}"
|
||||
CanDragItems="False"
|
||||
CanReorderItems="True"
|
||||
AllowDrop="False"
|
||||
SelectionMode="Single"
|
||||
SelectedItem="{Binding ListSelectedItem, Mode=TwoWay}"
|
||||
|
||||
IsDoubleTapEnabled="True"
|
||||
IsTapEnabled="True"
|
||||
|
||||
>
|
||||
<ListView.ItemTemplate>
|
||||
<!--ItemsSource="{Binding DisplayFileFolderItems}"-->
|
||||
|
||||
<!--<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel
|
||||
Orientation="Horizontal"
|
||||
@@ -65,23 +69,18 @@
|
||||
Style="{ThemeResource BaseTextBlockStyle}"
|
||||
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
|
||||
Margin="12,0,0,0"/>
|
||||
<ListView
|
||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
||||
ScrollViewer.HorizontalScrollBarVisibility="Auto"
|
||||
ScrollViewer.HorizontalScrollMode="Enabled"
|
||||
ScrollViewer.VerticalScrollMode="Disabled"
|
||||
ItemsSource="{Binding Labels}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<TextBlock Text="{Binding}"></TextBlock>
|
||||
</Grid>
|
||||
--><!--<controls:LabelListControl ItemsSource="{x:Bind Labels}">
|
||||
<DataTemplate x:DataType="model:LabelItem"></DataTemplate>
|
||||
--><!--<controls:LabelListControl.ItemTemplate>
|
||||
<DataTemplate x:DataType="model:LabelItem">
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</controls:LabelListControl.ItemTemplate>--><!--
|
||||
</controls:LabelListControl>--><!--
|
||||
|
||||
</StackPanel>
|
||||
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView.ItemTemplate>-->
|
||||
|
||||
<Custom:Interaction.Behaviors>
|
||||
<Custom1:EventTriggerBehavior EventName="DoubleTapped">
|
||||
|
||||
@@ -1,15 +1,64 @@
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using FileManager_UWP.ViewModel;
|
||||
using System.Collections.ObjectModel;
|
||||
using FileManager_UWP.Model;
|
||||
using System.Diagnostics;
|
||||
using FileManager_UWP.Controls;
|
||||
|
||||
namespace FileManager_UWP.View {
|
||||
|
||||
public sealed partial class FileListView : Page {
|
||||
|
||||
//public ObservableCollection<LabelItem> Labels =
|
||||
// new ObservableCollection<LabelItem>{
|
||||
// new LabelItem("照片"),
|
||||
// new LabelItem("土耳其摔跤"),
|
||||
// new LabelItem("李若明"),
|
||||
// new LabelItem("鸢晓曼"),
|
||||
// new LabelItem("才明洋与吴岳江进行土耳其摔跤"),
|
||||
// new LabelItem("真正的瑜伽大师")
|
||||
// };
|
||||
|
||||
private FileListViewModel vm;
|
||||
public FileListView() {
|
||||
this.InitializeComponent();
|
||||
vm = new FileListViewModel();
|
||||
DataContext = vm;
|
||||
vm.RefreshCommand.Execute(null);
|
||||
vm.PropertyChanged += Vm_PropertyChanged;
|
||||
}
|
||||
|
||||
private void Vm_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) {
|
||||
Debug.WriteLine(e.PropertyName);
|
||||
if (e.PropertyName == "DisplayFileFolderItems") {
|
||||
var items = (sender as FileListViewModel).DisplayFileFolderItems;
|
||||
MicroShitList.Items.Clear();
|
||||
foreach (var displayFileItem in items) {
|
||||
StackPanel sp = new StackPanel();
|
||||
sp.Height = 44;
|
||||
sp.Padding = new Windows.UI.Xaml.Thickness(12);
|
||||
sp.Orientation = Orientation.Horizontal;
|
||||
sp.SetValue(StackPanel.TagProperty, displayFileItem);
|
||||
|
||||
Image Icon = new Image();
|
||||
Icon.Source = displayFileItem.Icon;
|
||||
Icon.Height = 16;
|
||||
Icon.Width = 16;
|
||||
Icon.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Center;
|
||||
TextBlock Name = new TextBlock();
|
||||
Name.Text = displayFileItem.Name;
|
||||
Name.Margin = new Windows.UI.Xaml.Thickness(12, 0, 0, 0);
|
||||
|
||||
LabelListControl labels = new LabelListControl();
|
||||
labels.ItemsSource = displayFileItem.Labels;
|
||||
|
||||
sp.Children.Add(Icon);
|
||||
sp.Children.Add(Name);
|
||||
sp.Children.Add(labels);
|
||||
MicroShitList.Items.Add(sp);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||
>
|
||||
|
||||
<StackPanel>
|
||||
<StackPanel Name="MicroshitPanel">
|
||||
<TextBlock
|
||||
FontSize="50"
|
||||
Text="Test Label View" />
|
||||
@@ -23,8 +23,8 @@
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>-->
|
||||
|
||||
<controls:LabelListControl ItemsSource="{x:Bind Labels}" Tapped="LabelListControl_Tapped" />
|
||||
<controls:LabelListControl ItemsSource="{x:Bind empty}" />
|
||||
<!--<controls:LabelListControl ItemsSource="{x:Bind Labels}" />-->
|
||||
<!--<controls:LabelListControl ItemsSource="{Binding empty}" />-->
|
||||
|
||||
</StackPanel>
|
||||
</Page>
|
||||
@@ -1,4 +1,5 @@
|
||||
using FileManager_UWP.Model;
|
||||
using FileManager_UWP.Controls;
|
||||
using FileManager_UWP.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -40,6 +41,10 @@ namespace FileManager_UWP.View {
|
||||
public TestLabelView() {
|
||||
this.InitializeComponent();
|
||||
Debug.WriteLine(Labels.ToString());
|
||||
// MicroshitPanel;
|
||||
LabelListControl list1 = new LabelListControl();
|
||||
list1.ItemsSource = Labels;
|
||||
MicroshitPanel.Children.Add(list1);
|
||||
}
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e) {
|
||||
|
||||
@@ -4,6 +4,7 @@ using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
@@ -11,6 +12,16 @@ using Type = FileManager_UWP.Model.Type;
|
||||
|
||||
namespace FileManager_UWP.ViewModel {
|
||||
public class FileListViewModel: ViewModelBase {
|
||||
public ObservableCollection<LabelItem> Labels =
|
||||
new ObservableCollection<LabelItem>{
|
||||
new LabelItem("照片"),
|
||||
new LabelItem("土耳其摔跤"),
|
||||
new LabelItem("李若明"),
|
||||
new LabelItem("鸢晓曼"),
|
||||
new LabelItem("才明洋与吴岳江进行土耳其摔跤"),
|
||||
new LabelItem("真正的瑜伽大师")
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 当前路径
|
||||
/// </summary>
|
||||
@@ -45,6 +56,7 @@ namespace FileManager_UWP.ViewModel {
|
||||
|
||||
public RelayCommand RefreshCommand =>
|
||||
_refreshCommand ?? (_refreshCommand = new RelayCommand(async () => {
|
||||
Debug.WriteLine("Refresh");
|
||||
try {
|
||||
var fileService = new FileService();
|
||||
var fileList = await fileService.GetDisplayFileFolderList(Path);
|
||||
@@ -83,7 +95,9 @@ namespace FileManager_UWP.ViewModel {
|
||||
public RelayCommand DoubleTappedCommand =>
|
||||
_doubleTappedCommand ?? (_doubleTappedCommand = new RelayCommand(
|
||||
() => {
|
||||
Displayable i = ListSelectedItem as Displayable;
|
||||
StackPanel sp = ListSelectedItem as StackPanel;
|
||||
Displayable i = sp.GetValue(StackPanel.TagProperty) as Displayable;
|
||||
//Displayable i = ListSelectedItem as Displayable;
|
||||
Debug.WriteLine("Double tapped");
|
||||
if (i != null && (i.Type != Type.File)) {
|
||||
Path = i.Path;
|
||||
|
||||
Reference in new issue
Block a user