// Scroll event of the full size collection private void FullViewCollection_HorizontalScrollUpdated(object sender, int e) { // Calculate currently visible item var scrollProgress = FullViewCollection.ScrollX == 0 ? 0 : (double)FullViewCollection.ScrollX / FullViewCollection.ScrollXWidth; scrollProgress = scrollProgress < 0 ? 0 : scrollProgress; var position = (int)Math.Round(Items.Count * scrollProgress); if (_fullSizeTargetPosition >= 0 && _fullSizeTargetPosition != position) { // Wait until target position is reached return; } _fullSizeTargetPosition = -1; // My calculations are a bit off so i make sure that my index is not out of range :) position = position >= 0 ? position : 0; position = position > Items.Count - 1 ? Items.Count - 1 : position; // Check if the position updated to avoid unnecessary scroll to calls if (position != _currentPosition) { // Set the currently visible item as the target position for the preview collection to be in-sync _currentPosition = position; var middleImage = Items[position]; _previewTargetPosition = position; PreviewCollection.ScrollTo(middleImage, ScrollToPosition.Center); Debug.WriteLine("Full screen scrolled to position: " + position); } }
internal PostData( string id, string title, string author, int score, string url, string thumbnail, int num_comments, int?thumbnail_width, int?thumbnail_height, PreviewCollection preview) { ID = id; Title = WebUtility.HtmlDecode(title); Author = author; Score = score; Url = WebUtility.HtmlDecode(url); CommentCount = num_comments; Preview = preview; if (thumbnail.StartsWith("http")) { Thumbnail = new Image(thumbnail, thumbnail_width ?? -1, thumbnail_height ?? -1); } if (preview != null) { Preview = preview; } }
public MainViewModel() { CommandList = new ObservableCollection <CommandViewModel>(); AddCommandCommand = new RelayCommand(() => { var list = CommandList.Where(q => q.Name.StartsWith("Command")).ToList(); int maxNum = 0; foreach (var cmd in list) { var numStr = cmd.Name.Replace("Command", ""); int result; bool isConvert = int.TryParse(numStr, out result); if (isConvert) { if (maxNum < result) { maxNum = result; } } } maxNum++; var command = new CommandViewModel(); command.Name = "Command" + maxNum; command.AddSuccessStateCommand.Execute(null); this.CommandList.Add(command); }); DeleteCommandCommand = new RelayCommand <CommandViewModel>(command => { CommandList.Remove(command); }); UpdateCortanaCommand = new RelayCommand(() => { if (CommandList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0) { Messenger.Default.Send <string>("Commandの名前が重複しています", "error"); return; } CortanaXmlGenerator generator = new CortanaXmlGenerator(CommandPrefix, Example); foreach (var command in CommandList) { foreach (var state in command.StateList) { if (state is SuccessStateViewModel) { generator.AddCommandService(command.Name + "_" + state.Name, state.Example, state.ListenFor.Replace("\r", "").Split('\n'), state.FeedBack, voiceCommandServiceName); } else if (state is ScriptStateViewModel) { generator.AddCommandService(command.Name + "_" + state.Name, state.Example, state.ListenFor.Replace("\r", "").Split('\n'), state.FeedBack, voiceCommandServiceName); } else if (state is ProtocolStateViewModel) { generator.AddCommandNavigate(command.Name + "_" + state.Name, state.Example, state.ListenFor.Replace("\r", "").Split('\n'), state.FeedBack, voiceCommandServiceName); } } if (command.StateList.GroupBy(q => q.Name).Where(w => w.Count() > 1).Count() > 0) { Messenger.Default.Send <string>(command.Name + "コマンドのstateの名前が重複しています", "error"); return; } } Messenger.Default.Send <bool>(true, "updating"); var xml = generator.GenerateXml(); CurrentXml = xml; //Debug.Write(xml); OnRegisterVoiceCommand(xml); Messenger.Default.Send <bool>(false, "updating"); }); OnRegisterVoiceCommand += e => { }; ChangePassCodeCommand = new RelayCommand(() => { this.PassCode = Guid.NewGuid().ToString(); }); UpdatePreviewCommand = new RelayCommand(() => { PreviewCollection.Clear(); foreach (var command in CommandList) { if (command.StateList.Count > 0) { var preview = new CommandPreview( "コマンド「" + command.Name + "」を使用するにはこの発話をしてください", CommandPrefix + " " + command.StateList.First().FirstListenFor); PreviewCollection.Add(preview); } } }); InitializeCommand = new RelayCommand(() => { AddCommandCommand.Execute(null); }); CommandPrefix = "コルタナ"; Example = "こんにちはコルタナ"; ChangePassCodeCommand.Execute(null); ListWidth = 340; PreviewCollection = new ObservableCollection <CommandPreview>(); }