Click here to Skip to main content
15,887,293 members
Home / Discussions / WPF
   

WPF

 
QuestionCurrency Converter Pin
pjank427-Dec-12 5:44
pjank427-Dec-12 5:44 
AnswerRe: Currency Converter Pin
Pete O'Hanlon7-Dec-12 6:58
mvePete O'Hanlon7-Dec-12 6:58 
GeneralRe: Currency Converter Pin
pjank427-Dec-12 7:38
pjank427-Dec-12 7:38 
QuestionWPF Binding TextBox to Dependency Property Pin
g_ap5-Dec-12 1:02
g_ap5-Dec-12 1:02 
AnswerRe: WPF Binding TextBox to Dependency Property Pin
Richard Deeming5-Dec-12 2:53
mveRichard Deeming5-Dec-12 2:53 
Questionhighlight list view - is--moueOver Pin
dominioYP3-Dec-12 10:07
dominioYP3-Dec-12 10:07 
AnswerRe: highlight list view - is--moueOver Pin
SledgeHammer013-Dec-12 11:52
SledgeHammer013-Dec-12 11:52 
QuestionWPF DrawingContext DrawText bug??? Pin
subakaev2-Dec-12 21:09
subakaev2-Dec-12 21:09 
I'm writing a program that construct a huge diagram. Also this diagram can be save to png file. I have no problems when I render my diagram on WPF canvas. The problem start when I trying save it to file. DrawingContext.DrawText stop drawing the text with size==10 when horizontal text position becomes more than 11K pixels!

Here is the code that shows this effect.

I create simple WPF application project and create one class (MainViewControl):

Here is the code for MainViewControl.cs:
C#
class MainViewControl : FrameworkElement
    {
        public void Draw(DrawingContext context)
        {
            for (var i = 0; i < Width / 100; i++)
            {
                var text = new FormattedText((i * 100).ToString(CultureInfo.InvariantCulture), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Blue);
                var textPos = new Point((double)i * 100f + 0.789 - text.Width / 2, Height / 2 - text.Height / 2);
                context.DrawLine(new Pen(Brushes.Red, 1.0), new Point(i * 100, 0), new Point(i * 100, Height));
                context.DrawRectangle(Brushes.White, null, new Rect(textPos.X, textPos.Y, text.Width, text.Height));
                context.DrawText(text, textPos);
            }
        }

        protected override void OnRender(DrawingContext context)
        {
            Draw(context);
        }
    }
Here is the code for MainWindow.xaml:
C#
 <Window x:Class="DrawTextProblem.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:DrawTextProblem="clr-namespace:DrawTextProblem"
        Title="MainWindow" >
    <DockPanel>
        <Button Content="Save" Click="ButtonClick" DockPanel.Dock="Top" HorizontalAlignment="Left" />
        <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" DockPanel.Dock="Top">
            <DrawTextProblem:MainViewControl Width="50000" Height="200" x:Name="mainViewControl" />
        </ScrollViewer>
    </DockPanel>
</Window> 

When click the button I do this:
C#
private void ButtonClick(object sender, RoutedEventArgs e)
       {
           var dlg = new Microsoft.Win32.SaveFileDialog { FileName = "Image", DefaultExt = ".png", Filter = "Images (.png)|*.png" };

           if (dlg.ShowDialog() == true)
           {
               try
               {
                   var bounds = new Rect(0, 0, mainViewControl.Width, mainViewControl.Height);
                   var diagramBitmap = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, 96d, 96d, PixelFormats.Default);

                   var drawingVisual = new DrawingVisual();
                   var context = drawingVisual.RenderOpen();
                   context.DrawRectangle(Brushes.White, null, bounds);
                   mainViewControl.Draw(context);
                   context.Close();

                   diagramBitmap.Render(drawingVisual);

                   var imageFile = new FileStream(dlg.FileName, FileMode.Create, FileAccess.Write);

                   var encoder = new PngBitmapEncoder();
                   encoder.Frames.Add(BitmapFrame.Create(diagramBitmap));
                   encoder.Save(imageFile);
                   imageFile.Flush();
                   imageFile.Close();

                   MessageBox.Show("Image successfully saved.", "Image saved", MessageBoxButton.OK, MessageBoxImage.Information);
               }
               catch (Exception exception)
               {
                   MessageBox.Show(string.Format("Error:\n{0}", exception.Message), string.Empty, MessageBoxButton.OK, MessageBoxImage.Error);
               }
           }
       }

When I start this application I see MainViewControl on the MainWindow with all text labels every 100 pixels. If I click save button, text labels are disappearing in saved image after 11K pixels!

It's the same for text size = 10, 11 or 7, BUT not for 8, 9, 16 etc. Moreover, If I use text size 10.001 it works fine!

Does anybody know about this problem? It's a WPF bug?
GeneralRe: WPF DrawingContext DrawText bug??? Pin
TheIndra23-Nov-20 12:34
TheIndra23-Nov-20 12:34 
QuestionHow do you stop a WebBrowser object in WPF? Pin
Xarzu2-Dec-12 4:25
Xarzu2-Dec-12 4:25 
AnswerRe: How do you stop a WebBrowser object in WPF? Pin
Richard MacCutchan2-Dec-12 4:54
mveRichard MacCutchan2-Dec-12 4:54 
QuestionHow do you stop a WebBrowser object in WPF? Pin
Xarzu2-Dec-12 3:53
Xarzu2-Dec-12 3:53 
QuestionFlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 1:04
RugbyLeague30-Nov-12 1:04 
AnswerRe: FlowDocument - different coloured text in a word Pin
Pete O'Hanlon30-Nov-12 1:33
mvePete O'Hanlon30-Nov-12 1:33 
GeneralRe: FlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 1:50
RugbyLeague30-Nov-12 1:50 
AnswerRe: FlowDocument - different coloured text in a word Pin
Matt T Heffron30-Nov-12 7:46
professionalMatt T Heffron30-Nov-12 7:46 
GeneralRe: FlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 8:41
RugbyLeague30-Nov-12 8:41 
AnswerRe: FlowDocument - different coloured text in a word Pin
Matt T Heffron30-Nov-12 8:45
professionalMatt T Heffron30-Nov-12 8:45 
GeneralRe: FlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 8:48
RugbyLeague30-Nov-12 8:48 
GeneralRe: FlowDocument - different coloured text in a word Pin
RugbyLeague30-Nov-12 8:49
RugbyLeague30-Nov-12 8:49 
QuestionGrid.ColumnDefinition.setvalue Pin
caradri28-Nov-12 3:06
caradri28-Nov-12 3:06 
AnswerRe: Grid.ColumnDefinition.setvalue Pin
Matt T Heffron28-Nov-12 9:05
professionalMatt T Heffron28-Nov-12 9:05 
GeneralRe: Grid.ColumnDefinition.setvalue Pin
caradri28-Nov-12 20:12
caradri28-Nov-12 20:12 
QuestionGrid Pin
Ehsan Mashkouty28-Nov-12 0:01
Ehsan Mashkouty28-Nov-12 0:01 
QuestionSet Backgroundcolor when CheckBox in TreeView is checked Pin
Member 963452827-Nov-12 23:43
Member 963452827-Nov-12 23:43 

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.