private void OnPointerMovedOverBackgroundStackPanel(object sender, PointerRoutedEventArgs args) { if (!IsReadOnly) { var point = args.GetCurrentPoint(m_backgroundStackPanel); float xPosition = (float)point.Position.X; if (SharedHelpers.IsAnimationsEnabled()) { m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", xPosition); var deviceType = args.Pointer.PointerDeviceType; switch (deviceType) { case PointerDeviceType.Touch: m_sharedPointerPropertySet.InsertScalar("pointerScalar", c_touchOverScale); break; default: // mouse, TODO: MSFT distinguish pen later m_sharedPointerPropertySet.InsertScalar("pointerScalar", c_mouseOverScale); break; } } m_mousePercentage = (double)(xPosition) / CalculateActualRatingWidth(); UpdateRatingItemsAppearance(); args.Handled = true; } }
private void OnRepeaterElementPrepared(ItemsRepeater sender, ItemsRepeaterElementPreparedEventArgs args) { var element = args.Element; if (element != null) { var toggleButton = element as ToggleButton; if (toggleButton != null) { toggleButton.Checked += OnChildChecked; toggleButton.Unchecked += OnChildUnchecked; // If the developer adds a checked toggle button to the collection, update selection to this item. if (SharedHelpers.IsTrue(toggleButton.IsChecked)) { Select(args.Index); } } var repeater = m_repeater; if (repeater != null) { var itemSourceView = repeater.ItemsSourceView; if (itemSourceView != null) { element.SetValue(AutomationProperties.PositionInSetProperty, args.Index + 1); element.SetValue(AutomationProperties.SizeOfSetProperty, itemSourceView.Count); } } } }
// Menu Flyout actions private void ShowMenuFlyout() { if (m_button != null) { var width = m_button.ActualWidth; var height = m_button.ActualHeight; if (SharedHelpers.IsFlyoutShowOptionsAvailable()) { // Sets an exclusion rect over the button that generates the flyout so that even if the menu opens upwards // (which is the default in touch mode) it doesn't cover the menu bar button. FlyoutShowOptions options = new FlyoutShowOptions(); options.Position = new Point(0, height); options.Placement = FlyoutPlacementMode.Bottom; options.ExclusionRect = new Rect(0, 0, width, height); m_flyout.ShowAt(m_button, options); } else { m_flyout.ShowAt(m_button, new Point(0, height)); } if (m_flyout?.m_presenter != null) { m_flyout.m_presenter.KeyDown += OnPresenterKeyDown; _activeDisposables.Add(() => { m_flyout.m_presenter.KeyDown -= OnPresenterKeyDown; }); } } }
private void EnterGamepadEngagementMode() { double currentValue = Value; m_shouldDiscardValue = true; if (currentValue == c_noValueSetSentinel) { Value = InitialSetValue; // Notify that the Value has changed ValueChanged?.Invoke(this, null); currentValue = InitialSetValue; m_preEngagementValue = -1; } else { currentValue = Value; m_preEngagementValue = currentValue; } if (SharedHelpers.IsRS1OrHigher()) { ElementSoundPlayer.Play(ElementSoundKind.Invoke); } if (SharedHelpers.IsAnimationsEnabled()) { double focalPoint = CalculateStarCenter((int)(currentValue - 1.0)); m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", (float)(focalPoint)); } }
void SortElements(Rect visibleWindow) { // Sort in descending order (inVisibleWindow, phase) m_pendingElements.Sort((lhs, rhs) => { var lhsBounds = lhs.VirtInfo.ArrangeBounds; var lhsIntersects = SharedHelpers.DoRectsIntersect(lhsBounds, visibleWindow); var rhsBounds = rhs.VirtInfo.ArrangeBounds; var rhsIntersects = SharedHelpers.DoRectsIntersect(rhsBounds, visibleWindow); if ((lhsIntersects && rhsIntersects) || (!lhsIntersects && !rhsIntersects)) { // Both are in the visible window or both are not return(lhs.VirtInfo.Phase - rhs.VirtInfo.Phase); } else if (lhsIntersects) { // Left is in visible window return(-1); } else { return(1); } }); }
private void UpdateFallbackBrush() { if (_target.TryGetTarget(out var target)) { if (_micaController.Value == null) { // When not using mica, use the theme and high contrast states to determine the fallback color. ElementTheme GetTheme() { // See other IsRS3OrHigher usage for comment explaining why the version check and QI. if (SharedHelpers.IsRS3OrHigher()) { if (target is FrameworkElement targetTheme) { return(targetTheme.ActualTheme); } } var value = _uiSettings.GetColorValue(UIColorType.Background); if (value.B == 0) { return(ElementTheme.Dark); } return(ElementTheme.Light); } var theme = GetTheme(); Color GetColor() { if (_isHighContrast) { return(_uiSettings.GetColorValue(UIColorType.Background)); } if (theme == ElementTheme.Dark) { return(MicaController.DarkThemeColor); } else { return(MicaController.LightThemeColor); } } var color = GetColor(); target.Background = new SolidColorBrush(color); } else { // When Mica is involved, use transparent for the background (this is so that the hit testing // behavior is consistent with/without the material). target.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0)); } } }
private void OnLoaded(object sender, RoutedEventArgs args) { // If the NavViewItem is not prepared in an ItemPresenter it will be missing a reference to NavigationView, so adding that here. if (m_navigationView == null) { SetNavigationViewParent(SharedHelpers.GetAncestorOfType <NavigationView>(this)); } }
private RecyclingElementFactory GetElementFactory() { var elementFactory = new RecyclingElementFactory(); elementFactory.RecyclePool = new RecyclePool(); elementFactory.Templates["Item"] = SharedHelpers.GetDataTemplate(@"<TextBlock Text='{Binding}' Height='100' />"); return(elementFactory); }
// [TestMethod] Issue 1018 public void ValidateFocusMoveOnElementClearedWithUniqueIds() { ItemsRepeater repeater = null; CustomItemsSource dataSource = null; RunOnUIThread.Execute(() => { dataSource = new CustomItemsSourceWithUniqueId(Enumerable.Range(0, 5).ToList()); }); repeater = SetupRepeater(dataSource, "<Button Content='{Binding}' Height='10' />"); // dataSource: 0 1 2 3 4 // Index 0 deleted, focus should be on the new element which has index 0 SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Remove(0 /* index */, 1 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 0 /*expectedIndex */, "1" /* expectedContent */); } }); // dataSource: 1 2 3 4 // Last element deleted, focus should move to the previous element int lastIndex = dataSource.Inner.Count - 1; SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, lastIndex); }, () => { dataSource.Remove(lastIndex /* index */, 1 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 2 /*expectedIndex */, "3" /* expectedContent */); } }); // dataSource: 1 2 3 // Reset should keep the focused element as long as the unique id matches. SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Reset(); }, () => { int newIndex = dataSource.Inner.IndexOf(1); ValidateCurrentFocus(repeater, newIndex /*expectedIndex */, "1" /* expectedContent */); } }); // dataSource: 1 2 3 // Remove multiple elements SharedHelpers.RunActionsWithWait( new Action[] { () => { MoveFocusToIndex(repeater, 0); }, () => { dataSource.Remove(0 /* index */, 2 /* count */, true /* reset*/); }, () => { ValidateCurrentFocus(repeater, 0 /*expectedIndex */, "3" /* expectedContent */); } }); }
public FileSizeMetaInformation(long actual, long loaded) { ActualFileSize = actual; LoadedFileSize = loaded; //Get string versions LoadedFileSizeHuman = SharedHelpers.ByteSize(loaded); ActualFileSizeHuman = SharedHelpers.ByteSize(actual); }
protected override Size ArrangeOverride(Size finalSize) { Size result = finalSize; if (ScrollViewer is {} scrollViewer) { #if SCROLLVIEWER_SUPPORTS_ANCHORING if (SharedHelpers.IsRS5OrHigher()) { // No-op when running on RS5 and above. ScrollViewer can do anchoring on its own. scrollViewer.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); } else #endif { var shouldApplyPendingChangeView = scrollViewer != default && HasPendingBringIntoView && !m_pendingBringIntoView.ChangeViewCalled; Rect anchorElementRelativeBounds = default; var anchorElement = // BringIntoView takes precedence over tracking. shouldApplyPendingChangeView ? null : // Pick the best candidate depending on HorizontalAnchorRatio and VerticalAnchorRatio. // The best candidate is the element that's the closest to the edge of interest. GetAnchorElement(out anchorElementRelativeBounds); scrollViewer.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height)); m_pendingViewportShift = 0.0; if (shouldApplyPendingChangeView) { ApplyPendingChangeView(scrollViewer); } else if (anchorElement != default) { // The anchor element might have changed its position relative to us. // If that's the case, we should shift the viewport to follow it as much as possible. m_pendingViewportShift = TrackElement(anchorElement, anchorElementRelativeBounds, scrollViewer); } else if (scrollViewer != default) { m_pendingBringIntoView.Reset(); } m_candidates.Clear(); m_isAnchorElementDirty = true; _postArrange?.Invoke(this); } } return(result); }
private bool ShouldEnableAnimation() { // In ControlsResourceVersion2, animation is disabled. return // TODO Uno: Move XamlControlsResources to Uno.UI (#if !HAS_UNO !XamlControlsResources.IsUsingControlsResourcesVersion2() && #endif SharedHelpers.IsAnimationsEnabled()); }
private void ExitGamepadEngagementMode() { if (SharedHelpers.IsRS1OrHigher()) { ElementSoundPlayer.Play(ElementSoundKind.GoBack); } m_sharedPointerPropertySet.InsertScalar("starsScaleFocalPoint", c_noPointerOverMagicNumber); m_disengagedWithA = false; }
private void OnContainerContentChanging(ListViewBase sender, ContainerContentChangingEventArgs args) { var tabView = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this)); if (tabView != null) { var internalTabView = tabView; internalTabView.UpdateTabContent(); } }
public void BuildUp(NetInfo info, NetInfoVersion version) { /////////////////////////// // Template // /////////////////////////// var railVersionName = SharedHelpers.NameBuilder(SharedHelpers.TRAIN_TRACK, version); var railInfo = Prefabs.Find <NetInfo>(railVersionName); /////////////////////////// // 3DModeling // /////////////////////////// info.Setup10mMesh(version); /////////////////////////// // Set up // /////////////////////////// info.m_class = railInfo.m_class.Clone("APT" + railVersionName); info.m_halfWidth = 4.999f; //if (version == NetInfoVersion.Tunnel) //{ // info.m_setVehicleFlags = Vehicle.Flags.Transition; // info.m_setCitizenFlags = CitizenInstance.Flags.Transition; //} var lanes = new List <NetInfo.Lane>(); lanes.AddRange(info.m_lanes.ToList()); for (int i = 0; i < lanes.Count; i++) { if (lanes[i].m_direction == NetInfo.Direction.Backward) { lanes[i].m_direction = NetInfo.Direction.Forward; } } info.m_lanes = lanes.ToArray(); info.m_connectGroup = NetInfo.ConnectGroup.WideTram; info.m_nodeConnectGroups = NetInfo.ConnectGroup.WideTram | NetInfo.ConnectGroup.DoubleTrain | NetInfo.ConnectGroup.TrainStation; //var railInfos = new List<NetInfo>(); //railInfos.Add(railInfo); //railInfos.Add(Prefabs.Find<NetInfo>(NetInfos.Vanilla.TRAIN_STATION_TRACK, false)); //railInfos.Add(Prefabs.Find<NetInfo>("Train Cargo Track", false)); //for (int i = 0; i < railInfos.Count; i++) //{ // var ri = railInfos[i]; // //info.m_nodes[1].m_connectGroup = (NetInfo.ConnectGroup)9; // ri.m_connectGroup = NetInfo.ConnectGroup.DoubleTrain; // railInfo.m_nodeConnectGroups = NetInfo.ConnectGroup.DoubleTrain; // if (railInfo.m_nodes.Length > 1) // { // railInfo.m_nodes[1].m_connectGroup = NetInfo.ConnectGroup.DoubleTrain; // } //} }
public virtual void BuildUp(NetInfo info, NetInfoVersion version) { /////////////////////////// // Template // /////////////////////////// var railVersionName = SharedHelpers.NameBuilder(SharedHelpers.TRAIN_TRACK, version); var railInfo = Prefabs.Find <NetInfo>(railVersionName); info.m_class = railInfo.m_class.Clone("APT" + railVersionName); /////////////////////////// // Set up // /////////////////////////// info.m_hasParkingSpaces = false; //info.m_class = roadInfo.m_class.Clone(NetInfoClasses.NEXT_SMALL3L_ROAD); if (version == NetInfoVersion.Slope || version == NetInfoVersion.Tunnel) { info.m_halfWidth = 4; info.m_pavementWidth = 2; } else { info.m_halfWidth = 3; } //if (version == NetInfoVersion.Tunnel) //{ // info.m_setVehicleFlags = Vehicle.Flags.Transition; // info.m_setCitizenFlags = CitizenInstance.Flags.Transition; //} info.SetRoadLanes(version, new LanesConfiguration() { IsTwoWay = false, LanesToAdd = -1, }); info.m_connectGroup = NetInfo.ConnectGroup.SingleTrain; info.m_nodeConnectGroups = NetInfo.ConnectGroup.SingleTrain | NetInfo.ConnectGroup.DoubleTrain | NetInfo.ConnectGroup.TrainStation; var owPlayerNetAI = railInfo.GetComponent <PlayerNetAI>(); var playerNetAI = info.GetComponent <PlayerNetAI>(); if (owPlayerNetAI != null && playerNetAI != null) { playerNetAI.m_constructionCost = owPlayerNetAI.m_constructionCost * 1 / 2; playerNetAI.m_maintenanceCost = owPlayerNetAI.m_maintenanceCost * 1 / 2; } var trainTrackAI = info.GetComponent <TrainTrackAI>(); if (trainTrackAI != null) { } }
NavigationViewItem GetNavigationViewItem() { NavigationViewItem navigationViewItem = null; var item = SharedHelpers.GetAncestorOfType <NavigationViewItem>(VisualTreeHelper.GetParent(this)); if (item != null) { navigationViewItem = item; } return(navigationViewItem); }
protected override void OnItemsChanged(object item) { base.OnItemsChanged(item); var tabView = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this)); if (tabView != null) { var internalTabView = tabView; internalTabView.OnItemsChanged(item); } }
public BackdropMaterialState(Control target) { _dispatcherHelper = new DispatcherHelper(this); _target = new WeakReference <Control>(target); // Track whether we're connected and update the number of connected BackdropMaterial on this thread. _connectedBrushCount.Value++; CreateOrDestroyMicaController(); // Normally QI would be fine, but .NET is lying about implementing this interface (e.g. C# TestFrame derives from Frame and this QI // returns success even on RS2, but it's not implemented by XAML until RS3). if (SharedHelpers.IsRS3OrHigher()) { if (target is FrameworkElement targetThemeChanged) { void OnActualThemeChanged(FrameworkElement sender, object args) { UpdateFallbackBrush(); } targetThemeChanged.ActualThemeChanged += OnActualThemeChanged; _themeChangedRevoker = Disposable.Create(() => targetThemeChanged.ActualThemeChanged -= OnActualThemeChanged); } } void OnColorValuesChanged(UISettings uiSettings, object args) { _dispatcherHelper.RunAsync(() => UpdateFallbackBrush()); } _uiSettings.ColorValuesChanged += OnColorValuesChanged; _colorValuesChangedRevoker = Disposable.Create(() => _uiSettings.ColorValuesChanged -= OnColorValuesChanged); // Listen for High Contrast changes var accessibilitySettings = new AccessibilitySettings(); _isHighContrast = accessibilitySettings.HighContrast; void OnHighContrastChanged(AccessibilitySettings sender, object args) { _dispatcherHelper.RunAsync(() => { _isHighContrast = accessibilitySettings.HighContrast; UpdateFallbackBrush(); }); } accessibilitySettings.HighContrastChanged += OnHighContrastChanged; _highContrastChangedRevoker = Disposable.Create(() => accessibilitySettings.HighContrastChanged -= OnHighContrastChanged); UpdateFallbackBrush(); }
// TODO Uno specific: ensure the items are updated for ItemsSource change as Items are not yet in sync with ItemsSource properly internal override void OnItemsSourceSingleCollectionChanged(object sender, NotifyCollectionChangedEventArgs args, int section) { base.OnItemsSourceSingleCollectionChanged(sender, args, section); var tabView = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this)); if (tabView != null) { var internalTabView = tabView; var vectorChangedArgs = args.ToVectorChangedEventArgs(); internalTabView.OnItemsChanged(vectorChangedArgs); } }
private void RequestClose() { var tabView = SharedHelpers.GetAncestorOfType <TabView>(VisualTreeHelper.GetParent(this)); if (tabView != null) { var internalTabView = tabView; if (internalTabView != null) { internalTabView.RequestCloseTab(this, false); } } }
public UserInfo Check(string username, string password) { UserInfo userInfo = new UserInfo(); //密码加密 string pw = SharedHelpers.EncodeBase64(password); List <UserInfo> list = Queryable().ToList(); UserInfo User = list.Where(x => x.user_name == username && x.pass_word == pw).FirstOrDefault(); if (User != null) { userInfo = User; } return(userInfo); }
private void OnScrollViewerLoaded(object sender, RoutedEventArgs args) { if (sender is FrameworkElement scrollViewer) { var scrollContentPresenterFE = SharedHelpers.FindInVisualTreeByName(scrollViewer, "ScrollContentPresenter"); if (scrollContentPresenterFE != null) { if (scrollContentPresenterFE is ScrollContentPresenter scrollContentPresenter) { scrollContentPresenter.SizesContentToTemplatedParent = true; } } } }
private void SetScrollViewerProperties(string scrollViewerName, SerialDisposable revoker) { if (SharedHelpers.IsRS5OrHigher()) { if (GetTemplateChild(scrollViewerName) is ScrollViewer scrollViewer) { if (SharedHelpers.IsScrollContentPresenterSizesContentToTemplatedParentAvailable()) { scrollViewer.Loaded += OnScrollViewerLoaded; revoker.Disposable = Disposable.Create(() => scrollViewer.Loaded -= OnScrollViewerLoaded); } } } }
private void UpdateShadow() { if (SharedHelpers.IsThemeShadowAvailable()) { if (IsSelected && !m_isDragging) { Shadow = (ThemeShadow)m_shadow; } else { Shadow = null; } } }
private NavigationViewItem GetNavigationViewItem() { NavigationViewItem navigationViewItem = null; DependencyObject obj = this; var item = SharedHelpers.GetAncestorOfType <NavigationViewItem>(VisualTreeHelper.GetParent(obj)); if (item != null) { navigationViewItem = item; } return(navigationViewItem); }
protected override string GetNameCore() { string name = base.GetNameCore(); if (string.IsNullOrEmpty(name)) { if (Owner is PagerControl pagerControl) { name = SharedHelpers.TryGetStringRepresentationFromObject(pagerControl.GetValue(AutomationProperties.NameProperty)); } } return(name); }
private void UpdateIcon() { var templateSettings = TemplateSettings; var source = IconSource; if (source != null) { templateSettings.IconElement = SharedHelpers.MakeIconElementFrom(source); } else { templateSettings.IconElement = null; } }
private void InvalidateBrush() { // Delay brush updates until Tick to coalesce changes and avoid rebuilding the effect when we don't need to. if (!_needsBrushUpdate) { _needsBrushUpdate = true; SharedHelpers.QueueCallbackForCompositionRendering(() => { { UpdateBrush(); } _needsBrushUpdate = false; }); } }
protected override string GetNameCore() { string returnHString = base.GetNameCore(); // If a name hasn't been provided by AutomationProperties.Name in markup: if (string.IsNullOrEmpty(returnHString)) { var tvi = Owner as TabViewItem; if (tvi != null) { returnHString = SharedHelpers.TryGetStringRepresentationFromObject(tvi.Header); } } return(returnHString); }