protected override IControl GenerateView(object viewModel)
 {
     if (ViewBind.TryResolve(viewModel, out var view) && view is IControl control)
     {
         return(control);
     }
     return(new TextBlock()
     {
         Text = $"Cannot locate View for {viewModel}"
     });
 }
    public bool Draw(DrawingContext context, ref Rect rect, ITableCell c)
    {
        if (c is not SingleRecordDatabaseCellViewModel cell)
        {
            return(false);
        }

        if (cell.ActionCommand != null)
        {
            DrawButton(context, rect, cell.ActionLabel, 3, cell.ActionCommand.CanExecute(null));
            return(true);
        }

        if (cell.IsModified && cell.Parent.Entity.ExistInDatabase)
        {
            context.DrawRectangle(null, ModifiedCellPen, rect);
            // don't return true, because we want to draw original value anyway
        }

        if (cell.HasItems && !cell.UseFlagsPicker && !cell.UseItemPicker)
        {
            if (rect.Contains(mouseCursor))
            {
                var threeDotRect = GetThreeDotRectForCell(rect);
                DrawButton(context, threeDotRect, "...", 3);
                rect = rect.Deflate(new Thickness(0, 0, threeDotRect.Width, 0));
            }
        }

        if (cell.ParameterValue?.BaseParameter is IItemParameter && cell.TableField is DatabaseField <long> longField)
        {
            var icons = ViewBind.ResolveViewModel <IItemIconsService>();
            var icn   = icons.GetIcon((uint)longField.Current.Value);
            if (icn != null)
            {
                context.DrawImage(icn, new Rect(rect.X, rect.Center.Y - 18 / 2, 18, 18));
            }
            rect = rect.Deflate(new Thickness(20, 0, 0, 0));
        }

        return(false);
    }
 public async Task <bool> ShowDialog(IDialog viewModel)
 {
     try
     {
         if (UseExperimentalPopup)
         {
             var tcs   = new TaskCompletionSource <bool>();
             var popup = new Popup();
             popup.IsLightDismissEnabled = true;
             bool closed = false;
             popup.Height      = viewModel.DesiredHeight;
             popup.Width       = viewModel.DesiredWidth;
             popup.DataContext = viewModel;
             var pres = new ContentPresenter();
             ViewBind.SetModel(pres, viewModel);
             popup.Child = new Border()
             {
                 Child = pres, Background = Brushes.White, BorderThickness = new Thickness(1), BorderBrush = Brushes.DarkGray
             };
             viewModel.CloseCancel += () =>
             {
                 closed = true;
                 popup.Close();
                 tcs.SetResult(false);
             };
             viewModel.CloseOk += () =>
             {
                 closed = true;
                 popup.Close();
                 tcs.SetResult(true);
             };
             popup.GetObservable(Popup.IsOpenProperty).Skip(1).SubscribeAction(@is =>
             {
                 if (!@is && !closed)
                 {
                     closed = true;
                     tcs.SetResult(false);
                 }
             });
             if (FocusManager.Instance.Current is Control c)
             {
                 popup.PlacementTarget = c;
             }
             ((DockPanel)mainWindowHolder.Window.GetVisualRoot().VisualChildren[0].VisualChildren[0].VisualChildren[0]).Children.Add(popup);
             popup.PlacementMode = PlacementMode.Pointer;
             popup.IsOpen        = true;
             return(await tcs.Task);
         }
         else
         {
             DialogWindow view = new DialogWindow();
             view.Height      = viewModel.DesiredHeight;
             view.Width       = viewModel.DesiredWidth;
             view.DataContext = viewModel;
             return(await mainWindowHolder.ShowDialog <bool>(view));
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }