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

Change header of Treeview Context Menu

$
0
0

Hi 
I have a treeview with a context menu. 
On right click on each node, I have the option "Mark as read". 
Once clicked, I would like the text changes to "Mark as unread".

i write this

<TreeView Name="tvi" ><TreeView.Resources><ContextMenu x:Key ="TagContext"  StaysOpen="true"><MenuItem Header="Mark as read" Name="tviOption1" Click="markasreadClick"></MenuItem><!-- ... -->                      </ContextMenu></TreeView.Resources><!-- ... --></TreeView>
 private void markasreadClick(object sender, RoutedEventArgs e)
        {

           tviOption1.Header ="Mark as unread";
		   //...
        }

Unfortunately tviOption1 is not recognized in my C # code. 
Please, can you help me fix the problem?

Thanks


autonumber for datagridtextcolumn wpf C# ?

$
0
0
<DataGrid ItemsSource="{Binding customer}"    AutoGenerateColumns="False" Height="405" HorizontalAlignment="Left" Margin="12,95,0,0" Name="dgvreg" VerticalAlignment="Top" Width="786"  
     CanUserAddRows="True" 
           CanUserDeleteRows="True"
           CanUserSortColumns="True"
           CanUserReorderColumns="True"> 

<DataGrid.Columns >
                <DataGridTextColumn Header="CustomerID"  Binding="{Binding customer_id}" x:Name="id" />

 <DataGrid.Columns >

 </DataGrid>

How to use "CoWaitForMultipleHandles" ?

$
0
0

Hi

i develop WPF application with C#.

In my application, I use a thread that is processing a very long operation.  
After 60 seconds, I get an debugging error . To resolve this, I was advised to use CoWaitForMultipleHandles on all threads. 
I do not really mastered its use. 
Here is my code 
            System.Threading.Thread thread = new System.Threading.Thread(() =>
            {
                 loadingData();
                this.Dispatcher.Invoke((Action)(() =>
                { 
                    displayAlert("Done !");
                }));


            });

            thread.SetApartmentState(System.Threading.ApartmentState.STA);            
            thread.Start();



Please, can you help me to apply  CoWaitForMultipleHandles to my Thread? 
thank you.

WPF Datagrid. How to detect a binding error

$
0
0

I have a simple WPF application I'm playing with which contains a button (ButtonNew) and a DataGrid (GridResults). When the app is created a datatable is created which contains several columns (all of which have AllowDBNull set to false) along with some test data. This is then bound against the grid.

On the grid I have CanUserAddRows set to false. When I click ButtonNew I want to add a new row and let the user edit it. When the RowEditEnding event occurs how can I tell there is an error on the row? I can see the red exclamation mark against the row but I cannot see any (obvious) way of detecting the row is in error. Once the edit is complete then my plan is to set CanUserAddRows back to false. If I do this in RowEditEnding then I get an InvalidOperationException "'NewItemPlaceholderPosition' is not allowed during a transaction begun by 'AddNew'".

Code for the ButtonNew click handler:

private void ButtonNew_Click(object sender, RoutedEventArgs e)
{
    GridResults.Focus();
    GridResults.CanUserAddRows = true;
    GridResults.SelectedIndex = table.Rows.Count;
    GridResults.ScrollIntoView(GridResults.SelectedItem, GridResults.Columns[1]);
    GridResults.CurrentCell = new DataGridCellInfo(GridResults.SelectedItem, GridResults.Columns[1]);
    GridResults.BeginEdit();
}
Thanks,

Cheers, Mike

WPF + PRISM and Dynamic region

$
0
0

Dear all,

I need to get you though on a customer complex project I have to build.

In traditional WPF project I have done so far , I define the layout interface of the application by predefining grid area where I will insert different content.

Now I have a customer request project, where my customer would like to get a complete flexible application. By complete flexible application, my customer would like to be able to define by him self the area on the screen where Visual component will be place.

For that I have been guide from a previous post to explore "Composite UI" mechanism that PRISM can be provide . By exploring how flexible design need to be implemented, we need to define region area, and then map those region with a component.

That seems to be too simple for my customer. To add more stress on this, my customer would like to be able to define the Region area by himself with a tool, then decide what to insert in the define region.

For that, we have define a Grid layout on paper which looks as below :

Each small square in this grid represent the smallest area which is a 96 by 96 pixels size. Then the whole grid represent a ful HD resolution.

Starting from that grid we can use it as a canvas to place on that grid where we want to place our region.

For instance if my user want to place a button in top left corner of which as a Width of 192 and Height of 96, he will draw the region starting from Top corner of the grid which will occupy 2 cell of 96px in with and 1 cell of 96px in height.

Then once the region area is defined, my customer will select a component from a library button that he would like to attached to that predefined region.

So at the end we should have a kind of configuration file, which could be in XML formt with the following sample mapping :

RegionName ="Button1"; Colomn=0; Row=0; ColSpan=2 MapToView=ButtonView

Then once the customer as define all his region on the screen and map to a component (View), the configuration layout file is store somewhere, available to the client application.

Then the WPF client application, should then read that config file and build out of this the final layout dynamically. And of course all logic is plugged automatically between each component.

The more I think on this, and the more I think my customer would like to build a light version of Blend :-(

I need your though about this approach :

- how do you see the way to build the confutation tool for designing region area ?

- What could be the sample structure of the resulting XML configuration file ?

- Do you see any issue on building the final layout from client application side ?

Thanks for your advise and help on this as I start to be completely lost and need to be sure that all this will work fine or should work fine.

regards

serge

Datagrid set edit mode on and off based on cell click in data grid

$
0
0

I have a WPF datagrid and by default i have set the edit mode off. I have an update icon on the data grid, and when i click on the update icon on each row, i want the edit mode to set to on and first cell of the data grid should be focused.

I want to check if i click on update icon, first check if it is the update column and then set the isreadonly as true. I use the following code to do so, however, i get the sender as the entire datagrid not the cell.

How can i set the data grid property to edit mode on for one row, on click of update icon on that row.

<DataGridGrid.Row="2"Name="dgList"Margin="0,10,0,0"ItemsSource="{Binding List,Mode=TwoWay}"RowHeight="40"ColumnWidth="*"AutoGenerateColumns="False"CanUserAddRows="False"MouseLeftButtonDown="dgList_MouseLeftButtonDown"PreviewMouseLeftButtonDown="dgList_PreviewMouseLeftButtonDown"><DataGrid.Columns><DataGridTemplateColumnHeader="Image"MinWidth="250"IsReadOnly="True"><DataGridTemplateColumn.CellTemplate><DataTemplate><ImageSource="{Binding Path=Image, Converter={StaticResource ucconvertToImage}}"/></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn><DataGridTextColumnHeader="Name"MinWidth="250"Binding="{Binding Path=Name,Mode=TwoWay}"IsReadOnly="True"></DataGridTextColumn><DataGridCheckBoxColumnHeader="Is Active"MinWidth="250"Binding="{Binding Path=IsActive}"IsReadOnly="True"></DataGridCheckBoxColumn><DataGridTemplateColumnHeader="Update"MinWidth="50"MaxWidth="50"SortMemberPath="EditMode"IsReadOnly="False"><DataGridTemplateColumn.CellTemplate><DataTemplate><ImageSource="Icons/Update.jpg"></Image></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid>

privatevoid dgList_PreviewMouseLeftButtonDown(object sender,MouseButtonEventArgs e){DataGridCell cell = sender asDataGridCell;if(cell !=null){
                dgList.IsReadOnly=true;}}


Usefull dll of C++ for WPF and C#?

$
0
0

Hi,

I used to work with C++ more than 12 years so that I forgot everthing! Could someone give me some suggestion about C++ dll?

What features that are important for us to employ for WPF(C#) Project? What dll or where to load it?

I would like yo to list all interesting C++ dll here. In case, that features we cannot archive with C# so that we can use C++ dll.

Please list it for me.

Thanks and Best Regards,

WP

How to persist an image with superimposed Path objects?

$
0
0

Hello. I currently have an InkCanvas that contains an Image control. I'm using this to display an image by assigning a WriteableBitmap to the "Source" property of the Image control, as well as display certain interactive shapes superimposed on the image (and, ultimately, ink scribbles as well). The interactive shapes consist of complex Path objects that I add to the InkCanvas's "Children" collection.

At the moment everything is working well, but what I'd like to do now is somehow "flatten" the image and the shapes that are superimposed on it. In other words, I'd like to incorporate the Path objects into the image and save it as a standard jpg, tiff or whatever. Any ideas on how to proceed with this? Thank you in advance.

-L



A chance for YOU to play for the WPF team, in the TechNet Guru World Cup!

$
0
0

The World Cup is here again!

Not balls... brains!

And YOU have been selected to play on our team!

Yes forum reader, step up and take a shot!

Slam some techie tips in the back of our nets!

No dribbling please, just lots of problem tackling.

So come on Gurus and use your head!

Show us your skills, wow us with your technique, and win the hearts of your nation!

All you have to do is add an article to TechNet Wiki from your own specialist field. Something that fits into one of the categories listed on the submissions page. Copy in your own blog posts, a forum solution, a white paper, or just something you had to solve for your own day's work today.

Drop us some nifty knowledge, or superb snippets, and become MICROSOFT TECHNOLOGY GURU OF THE MONTH!

This is an official Microsoft TechNet recognition, where people such as yourselves can truly get noticed!

HOW TO WIN

1) Please copy over your Microsoft technical solutions and revelations toTechNet Wiki.

2) Add a link to it on THIS WIKI COMPETITION PAGE (so we know you've contributed)

3) Every month, we will highlight your contributions, and select a "Guru of the Month" in each technology.

If you win, we will sing your praises in blogs and forums, similar to the weekly contributor awards. Once "on our radar" and making your mark, you will probably be interviewed for your greatness, and maybe eventually even invited into other inner TechNet/MSDN circles!

Winning this award in your favoured technology will help us learn the active members in each community.

Feel free to ask any questions below.

More about TechNet Guru Awards

Thanks in advance!
Pete Laker


#PEJL

Got any nice code? If you invest time in coding an elegant, novel or impressive answer on MSDN forums, why not copy it over to the one and onlyTechNet Wiki, for future generations to benefit from! You'll never get archived again!

If you are a member of any user groups, please make sure you list them in the Microsoft User Groups Portal. Microsoft are trying to help promote your groups, and collating them here is the first step.


Get the full content : rss feed

$
0
0

Hi 
I developed a RSS reader. 
I use the following code to retrieve the date, title, description and link of each article from  rss link. 

            XmlDocument doc = new XmlDocument();
            doc.Load(link);
            XmlNodeList titleList = doc.SelectNodes("//item/title");
            XmlNodeList descriptionList = doc.SelectNodes("//item/description");
            XmlNodeList linkList = doc.SelectNodes("//item/link");
            XmlNodeList dateList = doc.SelectNodes("//item/pubDate");
           for (int x = 0; x <= titleList.Count ; x++)
            {
			//...
            }

I now seek to recover the full content of the article (without comments) and display it in my application. 
Can you help me with a code that can do that?

Thanks

Menu in a resource file that can be also used as ContextMenu

$
0
0

Hi everybody,

I would like to know if it is possible to create a menu (that can have submenus) in a resource file that can be used as Menu and also as a ContextMenu. Can you please give me a short example of the implementation in a Window ?

Thanks a lot for your help.

How to make WPF toolkit datepicker readonly

$
0
0
Can anyone pls let me know how WPF datepicker control can be made readonly .Even calendar image in control should be disabled.

cast objects from observablecollection and filter by criteria into DataGrid

$
0
0

I have a c# custom ObservableCollection, MyObservableCollection : ObservableCollection<MyClass>, that I am displaying in several different WPF windows.  I would like to display information about this collection, specifically members of MyInheritedClass : MyBaseClass in another window that meet certain criteria, say MyInheritedClass.PropertyA == true.  In particular, I want to display this filtered set in a WPF DataGrid.  I want to use the same MyObservableCollection as I use in the other windows so I only have to maintain one copy of the collection and have it automatically synced between the windows.  Note I don't have any experience with CollectionViews so if your answer involves this, please be specific so that I can understand it in this compound case.

To be more specific my shell classes are:

public class MyClass : INotifyPropertyChanged
{
     public MyClass() {}
     public event PropertyChangedEventHandler PropertyChanged;
}

public class MyInheritedClass : MyClass
{
     public MyInheritedClass() {}
     public bool PropertyA
     {
        get { return _PropertyA; }
        set
        {
            _PropertyA = value;
            if (PropertyChanged != null)
               PropertyChanged(this, new PropertChangedEventArgs("PropertyA"));
        }
     }
     private bool _PropertyA;
}

public class MyObservableCollection : ObservableCollection<MyClass>
{
     public MyObservableCollection() {}
}

public partial class MyWindow : Window
{
     public MyWindow(MyObservableCollection c)
     {
        InitializeComponent();
        myDataGrid.ItemsSource = c;
     }
}

Again, I want to display in the DataGrid in MyWindow only objects with PropertyA == true.  PropertyA is only a property of the inherited class.

Thanks!

Custom button click not firing

$
0
0

I have a custom style for a button and even setting the background to fill doesn't allow it to fire.. here is how I'm using it.  Basically, it puts a transparency behind all buttons in the grid by putting two borders one on top of the other..  

The click only seems to render from the border and nothing else.

<Grid.Resources><Style TargetType="Button"><Setter Property="HorizontalAlignment" Value="Center"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="Button"><Grid><Border Height="75" Width="75" CornerRadius="75" Opacity="0.25" Background="Black"/><Border Height="75" Width="75" CornerRadius="75" BorderBrush="White" BorderThickness="5" Background="Transparent"/></Grid></ControlTemplate></Setter.Value></Setter></Style></Grid.Resources><Button Grid.Column="0" Grid.Row="1" Click="playAnimation"/><Image Source="play.png" Grid.Column="0" Grid.Row="1" Tapped="playAnimation"/><TextBlock Grid.Column="1" Grid.Row="1" Text="Show" />


nagendra mishr

Context Menu for each node

$
0
0

Hello

I recently posted about it. 
http://social.msdn.microsoft.com/Forums/vstudio/en-US/67aa342e-b751-4148-8251-961bd54558e9/change-header-of-treeview-context-menu?forum=wpf 

I want to improve my question. 

I have a Treeview and for each node, there is a context menu where there is the option "Mark all as read" which turned into "Mark all as unread" in the following then click "Mark all as read" the third click. etc ... 

Based on my previous thread I get to change the text but the change applies to all nodes in the Treeview. 
I would like each node has its context menu that change does not act on the other. 

PS: the node number is not limited and each  new node should have the same properties. 
Thank you very much for your help.


Is it possible to add a SoundPlayer to a WPF view model?

$
0
0

Is it possible to add a SoundPlayer in a WPF view model like this one:

            public class UserViewModel : PropertyChangedBase
            {
                private string _alarmStatus = "Off";

                public string AlarmStatus
                {
                    get { return _alarmStatus; }
                    set
                    {
                        _alarmStatus = value;
                        OnPropertyChanged("AlarmStatus"); //This is important!!!
                    }
                }
            }

The usage of a SoundPlayer is normally like. I would want to include a way to play and stop the player:

        SoundPlayer sp = new SoundPlayer();
        sp.SoundLocation="alarmclock.wav";
        sp.Load();
        sp.PlayLooping();

Opening links from WPF WebBrowser control in default browser instead of IE

$
0
0
I am working on a WPF application that uses System.Windows.Controls.WebBrowser to display an embedded HTML page.
The problem I have is that all links from that page that are to open an external browser window (with target="_blank") open Internet Explorer instead of the configured default browser.
How do I tell the WebBrowser control to respect the default browser settings?

WPF DataGrid Bug?

$
0
0

Hi!

I have no idea what is goning on with this DataGrid!?

I have 10 active column...

I become 9 right back from the grid...!?

Here is the 10 column code:

<!-- Spalte10: "Errrror" - Text - <DataGridTemplateColumn Header="Spalte10" MinWidth="10" CanUserSort="True" x:Name="SP010"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBox Name="SP010" Text="{Binding GrSpalte10, Mode=TwoWay}" MaxLines="99" AcceptsReturn="True" TextWrapping="Wrap" AcceptsTab="True" HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" BorderThickness="0" MaxLength="256" /></DataTemplate></DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> -->

<DataGridTextColumn Header="Spalte10" MinWidth="10" CanUserSort="True" Binding="{Binding GrSpalte10, Mode=TwoWay}" x:Name="SP010"/>

I test the both column Versions...

The first will give me NOT back the "GrSpalte10" the second yes!?

I have two more column with the same structure (DataGridTemplateColumn...) there it will be working fine!?!?!

The next is that i have Problems to bring the result from "GrSpalte10" to another Array, there i lost the Information from the "GrSpalte10"!?

Have anyone an idea???

I can give you the code and so on if anyone that Need...

Best regards

Bernd

Multipass MeasureOverride() not calculating updated items size

$
0
0
I have a custom Panel with custom controls which should resize like RibbonButton, i.e. as the available size vary I should remove / add a header, resize an inner picture, etc...
 
Further the custom controls are lookless control, i.e. UI/Template is defined in the style, and I use triggers to update template element.
 
I communicate size setting from the panel to the individual controls by using an inherited attached property (I mean UI inheritance, like DataContext)
 
When I do my multi pass MeasureOverride() in my panel, when I call child.Measure(), it's as if my items are always the same size!!
Despite me changing the inherited attached property (and it does update inside control!)
To be clear my inside control don't resize, but when I change the inherited property, they change their UI template (to a smaller version)
 
Any clue how I can successfully implement RibbonButon and RibbonGroupPanel like behavior?

How to copy the contents of a WPF RichText Box without causing any performance delay (XamlWriter.Save())

$
0
0

Hi,

I am trying to copy the contents of a WPF richtext box and save it into a temperoray Rich TextBox.  I need to do this each time the text is changed in the RichText Box. Currently I am using XamlWriter.save to achieve this. But If I have about 60 lines already in RichTextBox, this is causing performance delay. 

I have uploaded sample code in skydrive link http://1drv.ms/VzN6LC

1. Open and run  the application

2. Click on the button and the contents will be loaded in the WPF RichTextBox

3. Now go to the last line in RichText and type some thing. There is a performance delay.

Please advise how to overcome this or an alternative to XamlWriter.save()


Viewing all 18858 articles
Browse latest View live


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