Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all 18858 articles
Browse latest View live

C# BitmapImage BitmapCacheOption issues when saving image

$
0
0

I'm running into a strange problem when loading BitmapImages from a URI, passing them through a CroppedBitmap and encoding / saving to an image in memory via a MemoryStream.

Code below:

System.Windows.Media.Imaging.BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(); bi.BeginInit(); // The BitmapCacheOption seems to be the source of the problem - // Setting it to OnLoad removes the issue but performance is 3-4x slower bi.CacheOption = System.Windows.Media.Imaging.BitmapCacheOption.None; bi.UriSource = new Uri(inputFile); bi.DecodePixelWidth = (int)imageViewBox[10]; bi.DecodePixelHeight = (int)imageViewBox[11]; bi.EndInit(); System.Windows.Media.Imaging.CroppedBitmap cbi = new System.Windows.Media.Imaging.CroppedBitmap(bi, new System.Windows.Int32Rect( (int)(imageViewBox[2] * imageViewBox[10]), (int)(imageViewBox[3] * imageViewBox[11]), (int)((imageViewBox[4] - imageViewBox[2]) * imageViewBox[10]), (int)((imageViewBox[5] - imageViewBox[3]) * imageViewBox[11]))); newImageSize = new Size(cbi.PixelWidth, cbi.PixelHeight); using (MemoryStream msOut = new MemoryStream()) { System.Windows.Media.Imaging.BmpBitmapEncoder enc = new System.Windows.Media.Imaging.BmpBitmapEncoder(); enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(cbi)); // Throws access violation exception intermittently when zoomed on some images enc.Save(msOut);

As commented in the code, the enc.Save line throws an AccessViolation exception intermittently (usually on larger images at 2 x zoom) when the BitmapCacheOption is set to None. Setting it to OnLoad resolves the issue. However, this is a performance critical part of the application, and OnLoad seems to hit performance by 3-400% which is not workable.

Even stranger, sometimes an exception is not thrown, and the image returned has regular vertical fault lines in it, as if it was missing a vertical line of pixels every n rows. Those missing pixels then get moved to the right hand of the image in a "compressed" mini-image!

Can anyone shed light on what might be happening here? I've tried using an OnDownload event handler, but it never seems to fire, and have tried testing for IsDownloading before proceeding with the rest of the method but it always returns false which seems to suggest that fully loading the image is not the issue here.


HwndHost - overritten functions like WndProc, TabIntoCore etc. get no invoke

$
0
0

We try to Host a Delphi Windo into a Wpf-Application, thats no problem, but there are some small problem.

We are not able to set the focus to the tab which contains the win32 Application. 

We tried to override the WndProc an some other functions, but they do not get the call.

There are any reasons why we do not get the call of these functions?

Registration form develop in MVVM using data base

$
0
0

Hi to all,

Any body tell me . How to impliment Registraton form in MVVM project architecture with data base using sql 2008.

my queries. 

1. I want to developer registration form.

2. Using MVVM.

3. Using data base connectivity sql 2008.

Please guide me .

Thanks.


A.Acharya Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Control.Template MenuItem

$
0
0

I have been learning a lot about general workflows for styles and templates. I am using Resource Dictionaries to store my styles and my applications brushes and colors. I am currently working on styles and control templates for certain elements of my UI and I am struggling with making a control template for the MenuItem.

Currently I have made a short style for a Menu and I am looking to put MenuItem's within it (just like the standard Menu and MenuItems) but I can't seem to get any MenuItem's to show when using my style.

Here is my code snippet of my XAML for my Menu:

<!--Top Level Menu--><Style x:Key="S2ENGINE.TopLevelMenu" TargetType="{x:Type Menu}"><Setter Property="Height" Value="32"/><!--Setting Menu Template--><Setter Property="Template"><Setter.Value><!--Menu Template--><ControlTemplate TargetType="{x:Type Menu}"><Menu Background="{StaticResource S2ENGINEGradientBrush}"
                          BorderBrush="{StaticResource S2ENGINEBorderBrushTransparent}"
                          BorderThickness="0"/></ControlTemplate></Setter.Value></Setter></Style>

Here is a code snippet of my XAML for my MenuItem: 

<!--Top Level MenuItems--><Style x:Key="S2ENGINE.TopLevelMenuItem" TargetType="{x:Type MenuItem}"><!--Setting MenuItems Template--><Setter Property="Template"><Setter.Value><!--Menu Template--><ControlTemplate TargetType="{x:Type MenuItem}"><MenuItem Foreground="{StaticResource S2ENGINETextBrush}"
                              FontFamily="Segeo UI Light"
                              FontSize="14"
                              Header="{TemplateBinding Header}"
                              Icon="{TemplateBinding Icon}"
                              IsCheckable="{TemplateBinding IsCheckable}"
                              ToolTip="{TemplateBinding ToolTip}"
                              BorderThickness="0"><!--Content Placement--><ContentPresenter x:Name="MenuItemContentPresenter"
                                              VerticalAlignment="Center"
                                              HorizontalAlignment="Center"/></MenuItem></ControlTemplate></Setter.Value></Setter></Style>

I have a separate Resource Dictionary called "Brushes.xaml" which is just storing SolidColorBrush and LinearGradientBrush to use in my styles (just in case you were wondering what the StaticResource's were).

Here is the usage in my MainWindow.xaml:

<Grid><StackPanel><Menu Style="{StaticResource S2ENGINE.TopLevelMenu}"><MenuItem Header="File" Style="{StaticResource S2ENGINE.TopLevelMenuItem}"/><MenuItem Header="Edit" Style="{StaticResource S2ENGINE.TopLevelMenuItem}"/></Menu></StackPanel></Grid>

And here is a screenshot showing the result in Designer View:

I have two Headers there and nothing is showing up at all. Not to sure where I am going wrong. Any help is appreciated! 

Thanks,

Dave.



How do I create a simple DataTemplate in C#?

$
0
0

I've been looking all morning to find some way of creating a simple, no data binding, data template. I've come across this article on Code Project titled Creating WPF Data Templates in Code: The Right Way quite often, but I believe it is overkill for what I'm trying to do. I'm trying to create a very simple, no databinding at all, data template which I want to use passing into a unit test. The referenced link goes into great detail about namespaces and the whole 9 yards. Something like this:

<DataTemplate><Grid><TextBlock Text="This is a test" /></Grid></DataTemplate>

So I think that article is giving me more than I need. So how do I accomplish this simply without pulling in everything including the kitchen sink?


Rod

Type universe cannot resolve assembly: System.Runtime

$
0
0

To All,

I've a wpf project that compile correctly no errors in vs13, but when I open in vs2015 the xaml designer compliants

Type universe cannot resolve assembly: System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.

The project compiles and run correctly, but the designer barf at the xaml files.

Probably a missing link?

Thanks


phil Chin

Center Menu Items

$
0
0

Hi,

I have a Menu control in my window and I am adding Menu Items to the Menu control. I am trying to figure out how to center those Menu Items within my Menu. 

Here is a screenshot:

My Menu Items are 16 x 16 in size and my Menu control is 32 x 32 in size. I want the Menu Item's to sit snug inside the Menu control, VerticalAlignment doesn't seem to work in my Menu Item tags. I've also tried adding a Grid in my Menu control and putting the Menu Item's inside that Grid but then the Menu Item's aren't stacked horizontally anymore (they are placed on top of each other). 

Do I need to edit the Menu control Style or the Menu Item Style?


Animations stutter while MediaElement is loading a Video

$
0
0

Hi,

I have a MediaElement which is loading a new video once a while. It takes 1-2 seconds on my system from setting the new MediaElement.Source until the video is fully loaded and ready to play. In the meantime another control performs a motion animation. This animation is stuttering horribly while the MediaElement loads the video.

I think the MediaElement is blocking the UI thread while loading.

How can I fix this problem? Is it possible to somehow tell the MediaElement to load the new Video asynchronously?

Regards, Paul


Microsoft WPF application - Mouse drag on Graph area

$
0
0

Hello,

In my wpf applciation where we used graph through .Net namespace (System.Windows.Controls.DataVisualization.Charting) and displaying it on Canvas.

As per customer need we have to work on graph where he can drag mouse on graph area (select some time section like in image). I want to use that selected start time/ end time  in a separate window to fetch another data.

for reference please refer below url but it is for web.

http://people.iola.dk/olau/flot/examples/selection.html


System.AccessViolationException + WPF (modern ui) + async (await)

$
0
0

My application is running on many computers, and has several tabs (pages).

But on a single computer, one of the tabs (pages) throws accessviolationexception.

This tab (page) is different from the others, so that there is "async- await" function.

In google I found that the problem is most likely in the computer. And offer the option of further research problem:
"How to perform a clean boot in Windows" (cant add link)
Maybe someone else knows how to solve the problem?

How to achieve Grouping and Ungrouping Canvas programmatically In wpf application

$
0
0
I want to group , ungroup canvas user control in wpf application.Though this can be achieved with microsoft visual studio in built function Group and Ungroup which we get from Object and Timeline window.Through ungrouping we are removing unwanted canvas and making only one parent(canvas) to child controls.
Phis i need to achieve programmatically.Please suggest how can I achieve this through programmatically though I want to process my xaml file without doing this manual step and handle it through code behind.

Below mentioned is code snippet of xaml data which is not yet grouped and after that grouping.

Code before ungrouping :

<Canvas Name="_01" RenderTransform="1, 0, 0, 1, 130.919685, -4.32">
          <Canvas Name="_64" RenderTransform="-0.999991, 0.004316, -0.004316, -0.999991, 14.637921, 2145.991988">
            <Path Name="_64_G0__MrkrEnd" Visibility="Collapsed" RenderTransform="3.31258, -1.721798, -1.721798, -3.31258, 5.998991, 1066.51392" StrokeLineJoin="Round" Data="M -1 -1 L 0 0 L 1 -1 ">
            </Path>
          </Canvas>
 </Canvas>
     
 Code after Ungrouping and grouping into a canvas, which allow a single parent node to the child.

 <Canvas Name="_01" RenderTransform="1, 0, 0, 1, 130.919685, -4.32">
        <Path x:Name="_64_G0__MrkrEnd" Visibility="Collapsed" StrokeLineJoin="Round" Data="M -1 -1 L 0 0 L 1 -1 " Canvas.Left="14.637" RenderTransformOrigin="0.5,0.5" Canvas.Top="2145.992"/>
        </Canvas>

Pankaj Deharia

Elementhost and derived WPF class

$
0
0

Hello,

I have a wpf class derived from System.Windows.Controls.Button

-- --- JButtonWPF.cs ---

using System.Windows;
using System.Windows.Controls;

namespace Jedox.Controls
{
    public partial class JButtonWPF : Button
    {
        public JButtonWPF()
        {
            dynamic ds = TryFindResource(ToolBar.ButtonStyleKey);
            if (ds is Style)
            {
                this.Style = ds;
            }
        }
    }
}

( This class has normally more code, but to create my Problem this is sufficient.)

Now I want to host an object of this type in one Windows.Form Dialog.

JButtonWPF Wpfb = new JButtonWPF();

this.btn_user.Child = Wpfb;

this.btn_user.PropertyMap.Remove("BackColor");
this.btn_user.PropertyMap.Remove("BackgroundImage");
this.btn_user.PropertyMap.Remove("BackgroundImageLayout");

When I open the dialog I see a black square, but when I move the mouse over the the button I see a gray  square.

When I comment out the line

this.Style = ds

in JButtonWPF.cs I see  gray square which doesn't Change when I move the mouse over the button, but the button isn't flat anymore.

So how can I achieve that this button has a "flat" style, but doesn't change automagically the Background.

tia

  Hendrik Schmieder

Describe all properties of UpdateSourceTrigger

$
0
0

Hi to all,

I did try  all  4 properties about UpdatesourceTrigger  . Default,LostFocus,PropertyChange and Explicit .

Trying this link :

http://www.c-sharpcorner.com/uploadfile/41e70f/overview-of-updatesourcetrigger-and-its-properties/

when i used all  4 properties in UpdateSourceTrigger , than not any changes in Source to destination .

Please give  any good example about Default , LostFocus , PropertyChange and Explicity .

Exacitly what changes when change all 4 properties in UpdateSourceTrigger .

Thnaks


A.Acharya Feedback to us Develop and promote your apps in Windows Store Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Image on Canvas

$
0
0

Good Day :) Help me realize my idea. I wont import jpg on canvas. If image big then size canvas i want see scroll like dataGrid when datagrid have many collomn and row. Which help me change visible zone.

I thy do  this 

<Canvas Grid.Column="1">
            <ScrollViewer>
            <Image x:Name="imBackLayer" Source="source\BackLayer.jpg"  Stretch="UniformToFill"></Image>
            </ScrollViewer>
        </Canvas>

but this not work


Unable to scroll to position in datagrid after datacontext refesh

$
0
0

When I refresh the datacontext I cannot get the scrollviewer to scroll back to its original position. For example, I scroll down to a row, double click to open a window and modify the content which updates a database, refresh the datacontext and then call scrollViewer.ScrollToVerticalOffset(offset). 

        void dg_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            scrollViewer = GetVisualChild<ScrollViewer>(dg);
            if (scrollViewer != null)
            {
                offset = scrollViewer.VerticalOffset;
            }

            int x = dg.SelectedIndex;
            int rowIndex = dg.SelectedIndex;
            int rowCount = dg.Items.Count - 1;
            try
            {
                CalendarItem currentCell = (CalendarItem)dg.CurrentCell.Item;

                if (currentCell != null)
                {
                    ModifyItem newModifyItemWindow = new ModifyItem(currentCell.ID, false);

                   bool?  DialogResult = newModifyItemWindow.ShowDialog();
                    if(DialogResult == true)
                    {
                        RefreshCalendar();
                    }
                }
            }
            catch (Exception)
            {
                return;
            }

            scrollViewer.ScrollToVerticalOffset(offset);
           // not working
        }

However, once the window has closed I can click on a button and the the datagrid scrolls correctly. I cannot find a way to make the scroll happen automatically.


:-( Still trying to program


ItemData for ComboBox in C# /WPF

$
0
0
I am quite new to C#/WPF. I am trying to bind a combo box to a list of items encapsulated by a class with members id and name in XAML. I am actually displaying the name in the combo box. I also need to associate the corresponding id to each name so that on selecting the name from the combo , I can get the associated id. Is there any method to do this in WPF? ie. is there any way to bind the id also ? Earlier there was the ItemData property with combo boxes.

C# WPF - How to select Multiple Items programatically in a Databound ListBox...

$
0
0

Using Windows Presentation Foundation for a Dialog.

The underlying code for the ListBox is:

   <ListBox Name="listBox1" Width="300" Height="600" Margin="0,0,5,0" SelectionMode="Multiple" />

My code saves data from this ListBox whether a single or multiple items are selected.

The ListBox has a hidden item which is the Key when the data is stored and the visible data which is shown.

---

The problem is that when attempting to select multiple items that are populated in the Listbox from the Database, I can only select 1 using "listBox1.SelectedIndex = xx;" where xx is the integer offset of the matching item. So this is not the right method to restore the items that were selected previously.

Using "listBox1.SelectedItems.Add(DisplayData);" where "DisplayData" is a string that matches exactly to what is in the ListBox does not select the desired items.

Using "ListBoxItem item = (ListBoxItem)listBox1.Items[xx]; // THIS line exits the subroutine!" which isn't helpful at all.

The IsSelected Property doesn't seem to be exposed so that I can use it to allow multiple ListBox items to be selected.

---

What am I missing?

Surely someone has successfully loaded a Databound ListBox and reselected Multiple Items after the ListBox has been loaded.

BillNew


DirectShow Filter Graph Spy: http://alax.info/blog/777 Extremely helpful for finding deep details for DirectShow Graphs.

WPF Treelistview with mousedown event

$
0
0

Hello Everyone,

starting my training, but sadly stuck on something probably everyone knows, so i am trying to make an event to happen on a child treeitemview, if user left clicks on it, I want a message box to appear, simple right?

sadly not for me :(

here is what i have so far, let me know what part i goofed up:

<TreeView x:Name="treeView" HorizontalAlignment="Left" Height="313" Margin="10,45,0,0" VerticalAlignment="Top" Width="215" Grid.ColumnSpan="2"><TreeViewItem Header="Sales" FontSize="15"><TreeViewItem Header="Customer" Name="SubTreeCustomer" MouseDown="SubTreeCustomer_MouseDown"></TreeViewItem><TreeViewItem Header="Sales Orders" Name="SubTreeSO"></TreeViewItem><TreeViewItem Header="Shipping" Name="SubTreeShip"></TreeViewItem></TreeViewItem><TreeViewItem Header="HR" FontSize="15"><TreeViewItem Header="Employee"></TreeViewItem></TreeViewItem><TreeViewItem Header="Purchasing" FontSize="15"><TreeViewItem Header="Purchase Order"/><TreeViewItem Header="Shipping" Height="21"/><TreeViewItem Header="Receiving"/></TreeViewItem>

and C#:

  public Details()
        {
            InitializeComponent();
            SubTreeCustomer.MouseDown += new MouseButtonEventHandler(SubTreeCustomer_MouseDown);
        }

        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void SubTreeCustomer_MouseDown(object sender, MouseButtonEventArgs e)
        {
            MessageBox.Show("Hello");
        }

thanks in advanced

Content Resizes With Element

$
0
0

I am having an issue with a Control Template that I am making. I have a Resource Dictionary that is storing all my brushes and paths for graphics. I have another Resource Dictionary that is storing all my Styles for my elements. I am working on a button Style and my goal is to be able to put any content inside the button and have that content resize when the button is resized.

To better illustrate what I mean here is some screenshots:

I have a button with a simple Path element as it's content

The button is using a Style within a Resource Dictionary. Here is the XAML for the Style:

<!--Flat Rounded Button--><Style x:Key="FlatRoundedButton" TargetType="{x:Type Button}"><!--Button Setters--><Setter Property="FontFamily" Value="Segeo UI Light"/><Setter Property="Foreground" Value="{StaticResource S2ENGINEHD.Text}"/><Setter Property="Width" Value="32"/><Setter Property="Height" Value="32"/><!--Setting Button Template--><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type Button}"><!--Button Template--><Border CornerRadius="2"
                            BorderThickness="0"
                            Background="{StaticResource S2ENGINEHD.Active}"><!--Content Placement--><ContentPresenter x:Name="ButtonContent"
                                          Content="{TemplateBinding Content}"
                                          Width="Auto"
                                          Height="Auto"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Center"/></Border></ControlTemplate></Setter.Value></Setter></Style> 

The result is this:

This looks great and is exactly what I am after but, when I resize my button the content doesn't resize to fit within the button:

Is it possible to make whatever content is inside the button resize properly. I have been messing around with the Content Presenter inside my Style and haven't really gotten anywhere. 

Thanks!

Powershell WPF window sizes Different when run outside of PS ISE.

$
0
0

Hey there,

I am currently working on a Powershell GUI Script utilising WPF. The problem Im having is that within the ISE when I run the script it all looks great. When I right click on the script from within the desktop environment and select "Run with Powershell", the windows are cropped. This occurs on all windows (Almost 20 windows in all).

I Would Ideally like to have the windows look exactly the same from whichever environment it is launched from. 

I have tried modifying the "MinHeight" and "MinWidth" properties within the XAML, but that pushes out the borders from within ISE.

The Resize option is set to "No Resize".

Any Help Would be Great.

Thanks.

J.

 

Viewing all 18858 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>