designTime Update ?

    public class BlockGrid : Grid
    {
        bool IsFirstTimeLoad = true;
        public BlockGrid()
        {
            if (!DesignerProperties.GetIsInDesignMode( this ))
            {
                this.Loaded += BlockGrid_Loaded;
            }
        }

        private void BlockGrid_Loaded( object sender, RoutedEventArgs e )
        {
            if(IsFirstTimeLoad)
            {
                this.IsFirstTimeLoad = false;
                DefinitionLoad();
                Panel.SetZIndex( this, this.ZIndex );
            }
        }

        private void DefinitionLoad()
        {
            if (!DesignerProperties.GetIsInDesignMode( this )/* && ColumnCount > 0 && RowCount > 0*/)
            {
                for (int c = 0; c < ColumnCount; c++)
                {
                    this.ColumnDefinitions.Add( new ColumnDefinition() );
                }
                for(int r = 0; r < RowCount; r++)
                {
                    this.RowDefinitions.Add(new RowDefinition() );
                }

                for(int col = 0; col < ColumnCount; col++)
                {
                    for(int row = 0; row < RowCount; row++)
                    {
                        var block = new Block
                        {
                            Margin = new Thickness( 2 ),
                            Title = String.Format("{0}x{1}", col, row),
                        };
                        Grid.SetColumn(block, col);
                        Grid.SetRow( block, row );
                        this.Children.Add( block );
                    }
                }
            }
        }

이와 같은 Custom Control Class가 있습니다.
동적으로 Column 과 Row를 추가해주고 있는데요,
Build를 하지 않은 상태에서 wpf designer에서 동적으로 추가된 항목들이 update 되어 보이질 않네요,
어떤 부분 때문일까요 ?

++추가
Build 해서 실행시키면 정상적으로 Display 됩니다.

1개의 좋아요

BlockGrid_Loaded() 메서드를

생성자에서 직접 호출해보시겠어요?

2개의 좋아요

변화가 없는 것 같습니다.

1개의 좋아요

테스트 해봤는데 정상 적으로 나옵니다.

DefinitionLoad() 메서드 코드에

if (!DesignerProperties.GetIsInDesignMode(this))

디자인 모드 실행이 아닐 경우만 로직 처리 되도록 되어 있습니다.
해당 분기 제거하면 잘 나옵니다.

수정한 코드 입니다.

public BlockGrid()
{
    if (!DesignerProperties.GetIsInDesignMode(this))
    {
        this.Loaded += BlockGrid_Loaded;
    }
    else
    {
        this.BlockGrid_Loaded(this, new RoutedEventArgs());
    }
}

추가로, private void DefinitionLoad() 내용에
if (!DesignerProperties.GetIsInDesignMode(this)/* && ColumnCount > 0 && RowCount > 0*/)
분기 제거


[xaml 디자이너 화면]

[xaml 코드]
image

2개의 좋아요

앗 되었습니다!!
디자이너가 생각보다 빠르게 반응을 안해서 안보여졌었던것 같네요!

감사합니다

1개의 좋아요