コード例 #1
0
        protected override async Task OnAfterRenderAsync(bool first_render)
        {
            if (first_render)
            {
                await UpdateColorSwatch();
            }

            if (!UpdatingPicker)
            {
                // For some reason, it takes two rounds of updates
                // to get the controls to line up. So, we set a flag
                UpdatingPicker = true;

                DomRect swatch_rect = await DomUtils.GetBoundingClientRect(JS, SwatchId);

                float pick_x = swatch_rect.left;
                float pick_y = swatch_rect.top + 50;

                PickerStyle  = "background-color: #444;";
                PickerStyle += "width: 200px; height: 200px;";
                PickerStyle += "position: fixed;";
                PickerStyle += $"left: {pick_x}px;";
                PickerStyle += $"top: {pick_y}px;";

                StateHasChanged();
            }
            else
            {
                UpdatingPicker = false;

                // Whend the picker is shown for the first time, we register our body click handler
                if (PickerShown)
                {
                    PickerShown = false;

                    if (m_net_obj == null)
                    {
                        m_net_obj = DotNetObjectReference.Create(this);
                    }

                    await JS.InvokeAsync <object>("RegisterOutsideClickDetector", PickerId, m_net_obj, "OnOutsideClick");
                }
            }

            await Log("Swatch OnAfterRenderAsync Finished");
        }