Click here to Skip to main content
15,898,588 members
Home / Discussions / WPF
   

WPF

 
QuestionWPF: How to make resizing custom datagrid column? [modified] Pin
MichalDawn11-Mar-09 22:58
MichalDawn11-Mar-09 22:58 
AnswerRe: WPF: How to make resizing custom datagrid column? Pin
ABitSmart11-Mar-09 23:40
ABitSmart11-Mar-09 23:40 
GeneralRe: WPF: How to make resizing custom datagrid column? Pin
MichalDawn11-Mar-09 23:51
MichalDawn11-Mar-09 23:51 
GeneralRe: WPF: How to make resizing custom datagrid column? Pin
ABitSmart11-Mar-09 23:53
ABitSmart11-Mar-09 23:53 
GeneralRe: WPF: How to make resizing custom datagrid column? [modified] Pin
MichalDawn12-Mar-09 0:02
MichalDawn12-Mar-09 0:02 
QuestionHow to render pixels of a bitmap correctly? Pin
Andy@11-Mar-09 5:03
Andy@11-Mar-09 5:03 
AnswerRe: How to render pixels of a bitmap correctly? Pin
Insincere Dave11-Mar-09 16:14
Insincere Dave11-Mar-09 16:14 
GeneralRe: How to render pixels of a bitmap correctly? Pin
Andy@12-Mar-09 2:59
Andy@12-Mar-09 2:59 
Thanks a lot for your anwser, it helps a lot.

The matrix bitmap is now correctly displayed.

To update the LEDs, i use a second bitmap, the _contentBmp, with the same size as the matrix bmp.
Now the matrix bmp is copied into the content bmp and for each LED whch is on, a bmp that represent the on status is copied into the content bmp.

The content bmp is now used in the OnRender().

A timer in the main window sets and resets the LEDs every 200 milli seconds:

MyCtrl.PixelEnabled = !MyCtrl.PixelEnabled


RenderTargetBitmap _pixelOffBmp;
RenderTargetBitmap _pixelGreenBmp;
RenderTargetBitmap _matrixBmp;
RenderTargetBitmap _contentBmp;


int _xMatrixPixel;
int _yMatrixPixel;
    
double _xUnitsMatrixBmp;
double _yUnitsMatrixBmp;


private bool _pixelEnabled = false;
public bool PixelEnabled
{
    get { return _pixelEnabled; }
    set
    {
        _pixelEnabled = value;
        UpdateDisplay();
    }
}


RenderTargetBitmap CreateMatrixBmp()
{
......	

    RenderTargetBitmap bmp = new RenderTargetBitmap(pixelWidthMatrixBmp, pixelHeightMatrixBmp, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);
    bmp.Render(drawingVisual);
    bmp.Freeze();

    _contentBmp = new RenderTargetBitmap(pixelWidthMatrixBmp, pixelHeightMatrixBmp, BMP_DPI, BMP_DPI, PixelFormats.Pbgra32);

    return bmp;
}       

void UpdateDisplay()
{
    RenderTargetBitmap pixelBmp;
    if (!PixelEnabled) pixelBmp = _pixelOffBmp;
    else pixelBmp = _pixelGreenBmp;

    DrawingVisual drawingVisual = new DrawingVisual();
    using (DrawingContext dc = drawingVisual.RenderOpen())
    {
        dc.DrawImage(_matrixBmp, new Rect(0, 0, _xUnitsMatrixBmp, _yUnitsMatrixBmp));

        double xOffset = 0;
        double yOffset = PIXEL_SPACE;
        for (int y = 0; y < _yMatrixPixel; y++)
        {
            xOffset = PIXEL_SPACE;
            for (int x = 0; x < _xMatrixPixel; x++)
            {
                if (x % 5 == 0)
                    dc.DrawImage(pixelBmp, new Rect(xOffset, yOffset, pixelBmp.Width, pixelBmp.Height));
                xOffset += pixelBmp.Width + PIXEL_SPACE;
            }

            yOffset += pixelBmp.Height + PIXEL_SPACE;
        }
    }
    _contentBmp.Render(drawingVisual);
}



protected override void OnRender(DrawingContext drawingContext)
{
    // base.OnRender(drawingContext);

    var pos = this.PointFromScreen(this.PointToScreen(new Point(0, 0)));
    double x = pos.X - Math.Floor(pos.X);
    double y = pos.Y - Math.Floor(pos.Y);
    drawingContext.DrawImage(_contentBmp, new Rect(1-x, 1-y, _contentBmp.Width, _contentBmp.Height));
}


Now the problem is that the CPU usage is about 50%!
The cause that the LayoutUpdated Event calls InvalidateVisual().
But without calling InvalidateVisual() the Bitmap is not correctly displayed if the size of the main window is changed by user.

The Sudoku sample is very interesting and i will study it exactly by the next opportunity.
But i´m skeptic about the performance.
Earlier than the approach with bitmaps, i´ve created a LED matrix with Shapes and that takes a lot of performance.

I like to create the LED matrix for simulating a LED Display, which can display text and graphic, the text can flash or it can by marquee text etc.

The size of the display can be 240 x 48 pixel, so i have 11520 controls.
GeneralRe: How to render pixels of a bitmap correctly? Pin
Insincere Dave12-Mar-09 6:56
Insincere Dave12-Mar-09 6:56 
GeneralRe: How to render pixels of a bitmap correctly? Pin
Andy@17-Mar-09 4:20
Andy@17-Mar-09 4:20 
QuestionBind an attached property Pin
Pauwels Bart11-Mar-09 3:55
Pauwels Bart11-Mar-09 3:55 
AnswerRe: Bind an attached property Pin
ABitSmart11-Mar-09 16:57
ABitSmart11-Mar-09 16:57 
QuestionRe: Bind an attached property Pin
Pauwels Bart11-Mar-09 19:45
Pauwels Bart11-Mar-09 19:45 
AnswerRe: Bind an attached property Pin
ABitSmart11-Mar-09 21:00
ABitSmart11-Mar-09 21:00 
QuestionRe: Bind an attached property Pin
Pauwels Bart11-Mar-09 22:33
Pauwels Bart11-Mar-09 22:33 
AnswerRe: Bind an attached property Pin
ABitSmart11-Mar-09 23:13
ABitSmart11-Mar-09 23:13 
GeneralRe: Bind an attached property Pin
Pauwels Bart12-Mar-09 0:54
Pauwels Bart12-Mar-09 0:54 
QuestionCan a WPF browser app be hosted on a server and accessed multiply by other users Pin
DimitarS10-Mar-09 21:56
DimitarS10-Mar-09 21:56 
AnswerRe: Can a WPF browser app be hosted on a server and accessed multiply by other users Pin
Pete O'Hanlon10-Mar-09 22:34
mvePete O'Hanlon10-Mar-09 22:34 
GeneralRe: Can a WPF browser app be hosted on a server and accessed multiply by other users Pin
DimitarS10-Mar-09 22:36
DimitarS10-Mar-09 22:36 
QuestionDecoupling WCF client proxy Pin
Mark J. Miller10-Mar-09 14:02
Mark J. Miller10-Mar-09 14:02 
QuestionTreeView vertical scrollbar bug Pin
Steve The Plant10-Mar-09 10:26
Steve The Plant10-Mar-09 10:26 
AnswerRe: TreeView vertical scrollbar bug Pin
ABitSmart10-Mar-09 17:23
ABitSmart10-Mar-09 17:23 
GeneralRe: TreeView vertical scrollbar bug Pin
Steve The Plant11-Mar-09 12:45
Steve The Plant11-Mar-09 12:45 
GeneralRe: TreeView vertical scrollbar bug Pin
Pete O'Hanlon11-Mar-09 22:26
mvePete O'Hanlon11-Mar-09 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.