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

Object Referene Issue- DragHelper

$
0
0

Hi All,

I am facing an issue in my WPF (MVVM) based appliation.

Issue is that i have a Text Box and a drop down , what ever value user enter's in the Text box we resolve it with Drop down and auto select the drop down with corresponding value.

and we do the resolution process on lost focus event of the TextBox and if value does not match we are showing a message box.

But when user enter's a wrong value in text box and focus is stll in text box and user hits on cancel button to cancel changes then as on cancel we are also showing a message box then two event get's fired as user clicked on cancel then lostfous of that textbox fired which eventualy trigerd resolution process and at the same time Cancel event got tigered now issue is that there is one message for value not getting resovled popping up from resolve method and one message from Cancel event for canceling change both message's comes togather .

Lost Focus event get's fired first.

Is there a way that we can know that which item has the latest focus (cancel button )from with in the resolve method of textbox?


Validating a textbox which will accept only negative decimal numbers.

$
0
0

Hi,

I am working on one Wpf Desktop application. In that I have to validate a textbox such that the user can enter a range from 0.0000 to-99999.0000. any one please suggest me how to do this. It shouldn't allow alphabets, space or any other special characters. thanks. 

Issue with tabbing through controls in wpf user control with WindowsFormHost

$
0
0

Hi,

I am using a  wpf user control to load as part of a word add in to launch and get user inputs for a letter template. Multiline text box was giving me issues here. It throws System.InvalidOperation exception "Dispatcher processing has been suspended, but messages are still being processed." This happened when the user tried to enter text, paste information etc. (Please note this template was developed for German Language Settings).

After several attempts, I decided to use a WindowsFormHost to host the textbox control within the wpf user control. Now the issue is that I am not able to tab through the controls. Once I reach the textbox, instead of going to the next control, it will just tab space inside the control. I came across the link below when I googled for some help on this topic.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/054d8509-dd2d-4b60-9b0a-383b0147e2ac/keyboard-focus-navigation-problem-with-elementhost-hosted-wpf-view-with-windowsformshost-hosted

I followed the suggestion Yves Zhang and created a custom panel control and wrapped the windows control inside it. However, focus does not move to the next control. The link with the sample code on the above link does not work either. Is it possible that someone would be able to send me the sample code mentioned here?

Many thanks,

Anu

If I target .net 4.5 but publish to a machine that has .net 4.0, how to make the application to run?

$
0
0

I has a web application that test ok when published to local IIS on Window 8. Then I publish the web app to a server machine that has .net 4.0. I get the error message: Parser Error Message: Unrecognized attribute "targetFramework" Note that attribute names are case-sensitive. Source Error: <compilation targetFramework="4.5"/><httpRuntime targetFramework="4.5" /> Source File: D:\Domains\xxxxxxxx.com\wwwrootweb.config Version Information: Microsoft.NET Framework version 2.0.50727.7026.

Then I log in to the server machine, make the following changes in Web.config file. <compilation targetFramework="4.0" /><httpRuntime targetFramework="4.0" /> Now my web site is down even I put the file App_offline.htm in the root directory. How can I fix this problem ? Thank you in advance.

RibbonComboBox SelectionChanged not firing

$
0
0

I'm developing an app in .NET 4.5.1 WPF/C#. I have added the Microsoft RibbonBar to the main window. On it, I have a RibbonComboBox which I populate at runtime with labels. Wen the user selects an item from the RibbonComboBox, however, it is not firing the SelectionChanged event.

Here is the code that populates the RibbonComboBox:

private void PopulateRibbonComboBox()
{
    Label label;    
    label = new Label();
    label.Content = "a";
    ribbonComboBox.Items.Add(label);

    label = new Label();
    label.Content = "b";
    ribbonComboBox.Items.Add(label);

    label = new Label();
    label.Content = "c";
    ribbonComboBox.Items.Add(label);
}

Here is the XAML for the RibbonBar:

<Ribbon><RibbonTab Header="Tab"><RibbonGroup Header="Group"><RibbonComboBox x:Name="ribbonComboBox" Label="Select an item:"><RibbonGallery Name="ribbonGallery" SelectionChanged="ribbonGallery_SelectionChanged"></RibbonGallery></RibbonComboBox></RibbonGroup></RibbonTab></Ribbon>

And finally, the C# code that handles the SelectionChanged event:

private void mapTypesRibbonGallery_SelectionChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
    RibbonGallery source = e.OriginalSource as RibbonGallery;
    if (source == null) return;
    Label selectedLabel = (Label)source;
}

However, when I run the program and select an item from the RibbonComboBox, the SelectionChanged event doesn't fire. Any ideas where I'm going wrong? I'm quite new to WPF/XAML and very new to the RibbonBar.

Thank you...


Fabricio Rodriguez Pretoria, South Africa

what would be the MVVM form of this simple test WPF app? (VS2012)

$
0
0

I am trying to grasp the idea of the MVVM pattern for WPF programming -- Data Binding, Commands, Templating.   I put together a very simple WPF app which on the button click event will copy the text content of textBox1 into textBox2  with a little bit of text appended to that.  I built this simple test WPF app based on the winform style -- the controls all have names and the button has a click event. Everything is fairly tightly coupled.  My question is this:  what would the app/guts (xaml, code behind) look like using the MVVM pattern? (code below) I guess I'm requesting if someone could rewrite this app using the MVVM pattern.  I tried to make it very simplistic so I could digest the material more easily.  One other question is this:  am I correct to understand that all WPF apps can be created using the MVVM pattern?  Or would there be some cases (like maybe this test app) where we are resigned to using the winform style?  I mean, maybe MVVM would be overkill for this simple app, but for the sake of learning MVVM, could this app be written using the MVVM pattern?  What would that look like?

--XAML code

<Window x:Class="WpfThing1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded"><Grid><Button Name="button1" Content="Button" HorizontalAlignment="Left" Height="33" Margin="82,40,0,0" VerticalAlignment="Top" Width="109" Click="Button_Click"/> <TextBox Name="textBox1" HorizontalAlignment="Left" Height="24" Margin="54,107,0,0" TextWrapping="Wrap" Text="testing" VerticalAlignment="Top" Width="210"/><TextBox Name="textBox2" HorizontalAlignment="Left" Height="23" Margin="54,154,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="210"/></Grid></Window>

--Code Behind

using System;
using System.Windows;

namespace WpfThing1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            button1.Click += (s, f) => { textBox2.Text = Thing1.ReadThing(textBox1.Text); };
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
        }
    }

    class Thing1
    {
        public static string ReadThing(string txt)
        {
            return txt + " -- return Thing";
        }
    }
}
Thanks


Rich P


adding,loading and saving to a listbox from a .txt file

$
0
0

Hi everyone im a beginner to wpf, and im looking for the simplest way to add information save and load(to and from a txt file)

all help would be greatly appriciated,thanks


             

Auto-update Column and ColumnSpan in Grid-contained elements

$
0
0

Hello,

I am 99% certain what it is I want to accomplish through some combination of Xaml and what's looking like probably some ValueConverter Bindings.

I need to update a Grid's ColumnDefinition via code and have design-time elements reorient themselves. One having its Column updated, and another its ColumnSpan, in response to the number of Columns.

However, I am having some trouble with the Xaml and/or ValueConverter(s) getting things wired up correctly.

The closest I've been is having the initial Column and ColumnSpan set through IMultiBindingConverter(s), then I set the ColumnDefinitions, and nothing else changes after that.

I've read up and down through SO, for example, and others have had the same difficulty. I've tried setting Mode OneWay, things like this, but to no avail.

I'm sure it's something simple I am missing, but I don't know. Would someone demonstrate a simple example how to connect a ValueConverter with a Grid Column, type thing?

Thanks...


Auto Calculate 2 cells difference in data-grid row and insert into cell in same row with bindings

$
0
0

Hi everyone and Happy New Year,

I am trying to create a datagrid with a start time column and end time column of a process followed by a third column that calculates automatically on input the time difference. The datas source come from a MSSQL server through a datatable and the start time and end times columns are in datetime datatypes. I should mention also that the data is input through the extended wpf toolkit datetimeupdown picker and I would like to have the data saved back to the MSSQL server through bindings. Im not sure how to proceed with this at all so if anybody knows how I could proceed with this I would be very thankful. Code would also be a bonus as I could not find a useful example of this on the internet.

Below is an image of my datagrid:

and the code to generate the first 3 columns.

<DataGridTemplateColumn Header="START OF TRANSFER" Width="*"><DataGridTemplateColumn.CellTemplate><DataTemplate ><TextBlock Height="18"><TextBlock.Text><Binding Path="STARTTRANSFER" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /></TextBlock.Text></TextBlock></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><wpfx:DateTimeUpDown  Format="Custom" FormatString="HH:mm"><wpfx:DateTimeUpDown.Value><Binding Path="STARTTRANSFER" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" /></wpfx:DateTimeUpDown.Value><wpfx:DateTimeUpDown.Text><Binding Path="STARTTRANSFER" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" /></wpfx:DateTimeUpDown.Text></wpfx:DateTimeUpDown></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn><DataGridTemplateColumn Header="END OF TRANSFER" Width="*"><DataGridTemplateColumn.CellTemplate><DataTemplate ><TextBlock Height="18"><TextBlock.Text><Binding Path="ENDTRANSFER" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /></TextBlock.Text></TextBlock></DataTemplate></DataGridTemplateColumn.CellTemplate><DataGridTemplateColumn.CellEditingTemplate><DataTemplate><wpfx:DateTimeUpDown  Format="Custom" FormatString="HH:mm"><wpfx:DateTimeUpDown.Value><Binding Path="ENDTRANSFER" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" /></wpfx:DateTimeUpDown.Value><wpfx:DateTimeUpDown.Text><Binding Path="ENDTRANSFER" UpdateSourceTrigger="PropertyChanged" Mode="TwoWay" /></wpfx:DateTimeUpDown.Text></wpfx:DateTimeUpDown></DataTemplate></DataGridTemplateColumn.CellEditingTemplate></DataGridTemplateColumn><DataGridTemplateColumn Header="TIME" Width="*" IsReadOnly="True" x:Name="test"><DataGridTemplateColumn.CellTemplate><DataTemplate><TextBlock HorizontalAlignment="Right" ><TextBlock.Text><Binding Path="DURATION" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" /></TextBlock.Text></TextBlock></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn>

thanks Callum

Why DateTime.TryParseExact return false on different culture ?

$
0
0

Why this statement return false

DateTime.TryParseExact("lun", "ddd", new CultureInfo("it"), DateTimeStyles.None, out dt)

while

new DateTime(2013, 11, 18).ToString("ddd", new CultureInfo("it"))

return "lun" ?

What's the mess with it ?

Can not commit changes made to SQL server Database from WPF code

$
0
0

Hi Guys,

Hope you can help me with this.

I have created a very simple program using WPF

in Microsoft Visual Studio 2013 Express, to Display , Update and delete data.

It works when compiled.

But never commit the changes made to the DB from my program.

Can someone help?????????

Here is the code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using System.Data.SqlClient;
using System.Data;

namespace myWPFusers
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    /// 
    
    public partial class MainWindow : Window
    {

        public SqlConnection ConStringOpen()
        {
        SqlConnection con = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=False;Context Connection=False ");
                    
        con.Open();

         return con;
        }

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
             
            ShowData();
        }

        public static int TryToParse(string value)
        {
            int number;
            bool result = Int32.TryParse(value, out number);
            if (result)
            {
                //Console.WriteLine("Converted '{0}' to {1}.", value, number);
                return number;
            }
            else
            {
                if (value == null) value = "";
                //Console.WriteLine("Attempted conversion of '{0}' failed.", value);
                return 0;
            }
        }


        public void ShowData()
        {
            //SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=True");
            //SqlConnection con = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=False;Context Connection=False ");
                    
            //con.Open();
            SqlConnection conn = ConStringOpen();

            SqlCommand comm = new SqlCommand("Select * from UserData", conn);
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter(comm);
            da.Fill(dt);
            listView1.DataContext = dt.DefaultView;
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {

            int Id = TryToParse(textBox3.Text);
            if (Id == 0 )
            {
                MessageBox.Show("Enter a Value to ID");
                MessageBox.Show(textBox3.Text);
                
            }
            else{
                  MessageBox.Show("Has Value");
                  MessageBox.Show(textBox3.Text);

                  string Username = textBox1.Text;
                  string password = textBox2.Text;
                  // SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True");
                  //SqlConnection con = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=False;Context Connection=False ");

                  
                  //con.Open();
                  SqlConnection conn2 = ConStringOpen();

                  
                 
                  SqlCommand comm = new SqlCommand("insert into UserData(Id,Username,Password) values(@id,@username,@password)", conn2);
                  //SqlCommand comm = new SqlCommand("insert into UserData(Username,Password) values(@username,@password)", con);
                  
                  comm.Parameters.AddWithValue("@id", Id);
                  comm.Parameters.AddWithValue("@username", textBox1.Text);
                  comm.Parameters.AddWithValue("@password", textBox2.Text);

                
                  comm.ExecuteNonQuery();
                 
                  
                  

                  //comm.ExecuteNonQueryAsync();

                  DataTable dt1 = new DataTable();
                  SqlDataAdapter da1 = new SqlDataAdapter(comm);
                              
                  da1.Update(dt1);



                  conn2.Close();

                  ShowData();

            }
            
            
        }

        private void btnClear_Click(object sender, RoutedEventArgs e)
        {
            //MessageBox.Show("Cleaniing");
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
        }

        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {

            if (listView1.SelectedItems.Count > 0)
            {
                DataRowView drv = (DataRowView)listView1.SelectedItem;
                string id = drv.Row[0].ToString();
                //SqlConnection con = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=False;Context Connection=False ");
                //con.Open();
                SqlConnection conn3 = ConStringOpen();
                SqlCommand comm = new SqlCommand("delete from UserData where Id=@id", conn3);

               

                comm.Parameters.AddWithValue("@id", id);
                comm.ExecuteNonQuery();

                DataTable dt2 = new DataTable();
                SqlDataAdapter da2 = new SqlDataAdapter(comm);

                da2.Update(dt2);

                conn3.Close();

                ShowData();
            }


        }

        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {


            if (listView1.SelectedItems.Count > 0)
            {
                DataRowView drv = (DataRowView)listView1.SelectedItem;
                string id = drv.Row[0].ToString();
                SqlConnection con = new SqlConnection(@"Data Source= (LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\dbUsers.mdf;Integrated Security=True;User Instance=False;Context Connection=False ");

                
                con.Open();
                SqlCommand comm = new SqlCommand("update UserData set username=@username,password=@password where Id=@id", con);
                comm.Parameters.AddWithValue("@id", id);
                comm.Parameters.AddWithValue("@username", textBox1.Text);
                comm.Parameters.AddWithValue("@password", textBox2.Text);
                

                comm.ExecuteNonQuery();

                con.Close();
                ShowData();
            }


        }

        
        

    }
}

I can save the UserControl to image in WPF, but the pictures is black

$
0
0

I can save all the UserControl to image. But all the pictures is dark when I click save button in the first time except current UserControl, That's ok when I click save button again.

This is my C# code:

public static void SaveView(UserControl viewName, int dpi, string fileName, string destFolder)
        {
            Rect bounds = VisualTreeHelper.GetDescendantBounds(viewName);

            int width = (int)viewName.RenderSize.Width;
            int height = (int)viewName.RenderSize.Height;

            if (width == 0 && height == 0)
            {
                width = 1920;
                height = 1080;
            }

            RenderTargetBitmap rtb = new RenderTargetBitmap(
                    width,
                    height,
                    dpi,
                    dpi,
                    PixelFormats.Pbgra32
                );


            DrawingVisual dv = new DrawingVisual();

            using (DrawingContext ctx = dv.RenderOpen())
            {
                VisualBrush vb = new VisualBrush(viewName);
                ctx.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
            }

            rtb.Render(viewName);

            try
            {
                PngBitmapEncoder jpgEncoder = new PngBitmapEncoder();
                jpgEncoder.Frames.Add(BitmapFrame.Create(rtb));

                Byte[] _imageArray;

                using (MemoryStream outputStream = new MemoryStream())
                {
                    jpgEncoder.Save(outputStream);
                    _imageArray = outputStream.ToArray();
                }

                //Try Find Save Path, if doesn't exists, create it.
                if (Directory.Exists(destFolder) == false)
                    Directory.CreateDirectory(destFolder);

                FileStream fileStream = new FileStream(Path.Combine(destFolder, fileName), FileMode.Create, System.IO.FileAccess.Write);

                fileStream.Write(_imageArray, 0, _imageArray.Length);
                fileStream.Close();
            }
            catch (Exception e)
            {
                Log4Net.Instance.Info(System.Reflection.MethodInfo.GetCurrentMethod().ToString());
                Log4Net.Instance.Info("Exception Generate Screenshot: " + fileName);
                Log4Net.Instance.Info(e.StackTrace.ToString());
                Debug.WriteLine(e.ToString());
            }
        }

Many thanks in advance.

Datagridcell text change not updating the source in viewmodel.

$
0
0

Hi,

I have created a datagrid with DataGridTextcolumn dynamically. Few columns are read only and few are not. Based on the user action I need to set the read only for a specific cell in data grid. I need to do everything dynamically. For this I have created DataGridTextColumn with read only as false. After that based on user actions and conditions, setting the cell as either editable or not. For that I did like below.

//////////////////////////////////////// Code /////////////////////

 Style style = new Style(typeof(DataGridCell));

            DataTrigger dt = new DataTrigger();
            dt.Binding = new Binding(a_editableBindingPropertyPath);

            ControlTemplate clt = new ControlTemplate();          
            clt.TargetType = typeof(DataGridCell);

            Binding bd2 = new System.Windows.Data.Binding();
            bd2.RelativeSource = new RelativeSource(RelativeSourceMode.TemplatedParent);
            bd2.Path = new PropertyPath("Content.Text");
            bd2.Mode = BindingMode.TwoWay;
            bd2.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

            FrameworkElementFactory m_borderFWElementFactory = new FrameworkElementFactory(typeof(Border));
            FrameworkElementFactory m_textFWElementFactory = new FrameworkElementFactory(typeof(TextBox));

           
            m_textFWElementFactory.SetBinding(TextBox.TextProperty, bd2);
            m_textFWElementFactory.SetValue(TextBox.IsReadOnlyProperty, false);
            m_textFWElementFactory.SetValue(TextBox.BackgroundProperty, Brushes.White);
           
            m_borderFWElementFactory.AppendChild(m_textFWElementFactory);

            clt.VisualTree = m_borderFWElementFactory;


            Setter s = new Setter(DataGridCell.TemplateProperty, clt);
            dt.Value = "true";

            dt.Setters.Add(s);

            style.Triggers.Add(dt);

            dataGridTextColumn.CellStyle = style;

////////////////////////////////////////

But I am facing one problem. Whenever text in cell changes, its not updating the binding source.

Can somebody suggest me what could be done.

Regards,

Mohan.

How do I shrink the margin around the DataGridColumnHeader in the DataGrid

$
0
0

I am trying to shrink the margin between headers in a DataGrid. I tried styling the DataGridColumnHeader and setting margin/padding/min height to 0 with no success. I think that the DataGridColumnHeader is being contained in another object, and that I need to set the relevant properties on that, but I do not have access to Expression Blend and have not been able to find the default template online. Does anyone have the default template I am looking for and/or know a better way to do this?

Thank you,

How to get "Select File" dialog via browse button in the property list of properties window?

$
0
0

Hi,

I want to add a property to a C#/WPF user control allowing a "Select File" dialog via browse button in the property list, just like ImageUrl property of Image control so that i can get the path of the image and display it

Thanks in advance,

Gaurav


Scrolling using mouse wheel in a WPF Tab Control not working as expected when hosted within a tool window in Visual Studio 2010

$
0
0

We have a VS 2010 C# VsPackage with a tool window that hosts a WPF user control. The user control has a tab control with 2 tabs, one with a few combo boxes and the other with a list view. 

<Grid><TabControl><TabItem Header="tabItem1" Name="tabItem1"><ScrollViewer><Grid><Grid.RowDefinitions><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /><RowDefinition Height="Auto" /></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition /><ColumnDefinition /></Grid.ColumnDefinitions><ComboBox Name="comboBox1" Grid.Row="0" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1"/><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox2" Grid.Row="1" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox3" Grid.Row="2" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox4" Grid.Row="3" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox5" Grid.Row="4" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox6" Grid.Row="5" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1"/><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox7" Grid.Row="6" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox><ComboBox Name="comboBox8" Grid.Row="7" Grid.Column="0" Margin="20"><ComboBoxItem Content="comboBoxItem1" /><ComboBoxItem Content="comboBoxItem2" /><ComboBoxItem Content="comboBoxItem3" /><ComboBoxItem Content="comboBoxItem4" /><ComboBoxItem Content="comboBoxItem5" /></ComboBox></Grid></ScrollViewer></TabItem><TabItem Header="tabItem2" Name="tabItem2"><Grid><ListView Name="listView1" Margin="20"><ListViewItem Content="listViewItem1" /><ListViewItem Content="listViewItem2" /></ListView></Grid></TabItem></TabControl></Grid>

There is a scroll viewer around the combo boxes in the first tab. When I run a WPF application with a window that hosts this user control, I do not see any problem. When the same control is hosted in a tool window, the scroll behaviour using the mouse wheel is problematic. When I open the tool window, click the second tab, select a list view item, click the first tab again, and use the mouse wheel to scroll, I see the first combo box selection changes. I expect the whole page to scroll instead, just like it did in the WPF Application.

I tried hosting the same control in a Windows Forms Application, I don't see the problem. Also, I don't see the problem if I run the VsPackage in VS 2012.

Is there a way I can workaround this issue?

Thanks,
Priya

Question about sorting Detail table

$
0
0

Someone posted almost the exact same question here.  I attempted to use that answer in my situation but am not sure how to form the syntax.  I'm using WPF and EF.

I, too, have a master/detail situation that uses a combo box that fills a datagrid.  The combo is sorted by patient name.  I'd like the grid to sort by appointment date.

The EF wizard created the following code (I added the sort description).

        Dim TblPatientDemographicViewSource As System.Windows.Data.CollectionViewSource =
            CType(Me.FindResource("TblPatientDemographicViewSource"), System.Windows.Data.CollectionViewSource)

        'sort view by patient name.  
        TblPatientDemographicViewSource.SortDescriptions.Add(New SortDescription("PatientName", ListSortDirection.Ascending))

        'Load data by setting the CollectionViewSource.Source property:
        'TblPatientDemographicViewSource.Source = [generic data source]
        _context.tblPatientDemographics.Load()
        TblPatientDemographicViewSource.Source = _context.tblPatientDemographics.Local

The suggested answer (converted to vb.net from c#):

        DirectCast(TblDentistAppointmentsDataGrid.Items, ItemCollection).SortDescriptions.Add(New System.ComponentModel.SortDescription("DentistAppointmentDate", System.ComponentModel.ListSortDirection.Ascending))

I'm not sure where to place this suggested code in my code block.  More importantly, I'm not sure the syntax is correct.  Looking at the xaml, I noticed the resource name:

<DataGrid x:Name="TblDentistAppointmentsDataGrid" AutoGenerateColumns="False" EnableRowVirtualization="True" 
                  ItemsSource="{Binding Source={StaticResource TblPatientDemographictblDentistAppointmentsViewSource}}" 
I thought maybe that resource is what I should apply the sort description to but that is not an option when forming the syntax. 

Thanks.


how to select easily a DataTemplate from App.Xaml

$
0
0

Dear all,

I have the following DataTemplate in my App.Xaml

<DataTemplate DataType="{x:Type vmodels:FilterViewModel}" ><!--<v:FilterView DataContext="{Binding}"/>--><v:NewFilterView DataContext="{Binding}"/></DataTemplate>

For the time being as you can see I have a commented FilterView but in my final app, I need to be able to select either the FilterView or the NewFilter view based on a Setting in my app.config

What woul be the best way to make this selection ?

IN orther control I have used TemplateSelector but here it is a bit different as I am dynamically instanciate proper control based on the same ViewModel

Thnaks for tips

Random hang-up when showing a dialog on a touchscreen on Win8

$
0
0

Hello,

We are developing an application with VS2010, C#, WPF  and NET Framework 4.0.

The application is having random hang-ups after showing a dialog.

This problem only happens on Win8 and with a touchscreen. On WinXP or Win7 no problems.

Below the stack trace of the deadlock :

0:009> ~0s eax=00000001 ebx=00000001 ecx=00c450a0 edx=00c450a0 esi=00000002 edi=00000002 eip=77577174 esp=00b8baa8 ebp=00b8bc2c iopl=0 nv up ei pl zr na pe nc cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000246 ntdll!KiFastSystemCallRet: 77577174 c3 ret 0:000> !clrstack OS Thread Id: 0x10e4 (0) Child SP IP Call Site 00b8bf38 77577174 [HelperMethodFrame_1OBJ: 00b8bf38] System.Threading.SynchronizationContext.WaitHelper(IntPtr[], Boolean, Int32) 00b8c1dc 669c5af2 System.Windows.Threading.DispatcherSynchronizationContext.Wait(IntPtr[], Boolean, Int32) 00b8c1f0 679113d6 System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext, IntPtr[], Boolean, Int32) 00b8c428 685f2652 [GCFrame: 00b8c428] 00b8c4f4 685f2652 [HelperMethodFrame_1OBJ: 00b8c4f4] System.Threading.WaitHandle.WaitOneNative(System.Runtime.InteropServices.SafeHandle, UInt32, Boolean, Boolean) 00b8c5c0 6799d2f2 System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle, Int64, Boolean, Boolean) 00b8c5dc 6799d2b8 System.Threading.WaitHandle.WaitOne(Int32, Boolean) 00b8c5f0 6799d328 System.Threading.WaitHandle.WaitOne() 00b8c5f8 665225e6 System.Windows.Input.PenThreadWorker.WorkerGetTabletsInfo() 00b8c62c 6653d833 System.Windows.Input.TabletDeviceCollection.UpdateTablets() 00b8c680 667373c3 System.Windows.Input.TabletDeviceCollection..ctor() 00b8c690 66052e20 System.Windows.Input.StylusLogic.get_TabletDevices() 00b8c6a0 6644e4cf System.Windows.Input.StylusLogic.OnDeviceChange() 00b8c6ac 6644e9f2 System.Windows.Input.StylusLogic.HandleMessage(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr) 00b8c6dc 6584e3a4 System.Windows.SystemResources.InvalidateTabletDevices(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr) 00b8c6f0 65bf1e1b System.Windows.SystemResources.SystemThemeFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 00b8c704 669c698b MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef) 00b8c740 669c68db MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object) 00b8c750 669c6756 System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32) 00b8c770 669c668a MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate) 00b8c7b4 669c4cae System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32) 00b8c808 669c61e1 MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr) 00b8cd98 00dba0b6 [HelperMethodFrame_1OBJ: 00b8cd98] System.Threading.SynchronizationContext.WaitHelper(IntPtr[], Boolean, Int32) 00b8d03c 669c5af2 System.Windows.Threading.DispatcherSynchronizationContext.Wait(IntPtr[], Boolean, Int32) 00b8d050 679113d6 System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext, IntPtr[], Boolean, Int32) 00b8d288 685f2652 [GCFrame: 00b8d288] 00b8d954 685f2652 [GCFrame: 00b8d954] 00b8decc 685f2652 [HelperMethodFrame_1OBJ: 00b8decc] System.StubHelpers.InterfaceMarshaler.ConvertToManaged(IntPtr, IntPtr, IntPtr, Int32) 00b8df58 66418fe6 DomainBoundILStubClass.IL_STUB_PInvoke(System.Guid ByRef, System.Object, Int32, System.Guid ByRef) 00b8df5c 66511897 [InlinedCallFrame: 00b8df5c] MS.Win32.Penimc.UnsafeNativeMethods.CoCreateInstance(System.Guid ByRef, System.Object, Int32, System.Guid ByRef) 00b8dfc4 66511897 MS.Win32.Penimc.UnsafeNativeMethods.CreatePimcManager() 00b8dff0 665118d2 MS.Win32.Penimc.UnsafeNativeMethods..cctor() 00b8e168 685f2652 [GCFrame: 00b8e168] 00b8ea30 685f2652 [PrestubMethodFrame: 00b8ea30] MS.Win32.Penimc.UnsafeNativeMethods.CreateResetEvent(IntPtr ByRef) 00b8ea58 665221b3 System.Windows.Input.PenThreadWorker..ctor() 00b8ea90 66521e6b System.Windows.Input.PenThreadPool.GetPenThreadForPenContextHelper(System.Windows.Input.PenContext) 00b8eab0 66521f47 System.Windows.Input.PenThreadPool.GetPenThreadForPenContext(System.Windows.Input.PenContext) 00b8eac4 6653d814 System.Windows.Input.TabletDeviceCollection.UpdateTablets() 00b8eb18 667373c3 System.Windows.Input.TabletDeviceCollection..ctor() 00b8eb28 66052e20 System.Windows.Input.StylusLogic.get_TabletDevices() 00b8eb38 66052cc2 System.Windows.Input.StylusLogic.RegisterHwndForInput(System.Windows.Input.InputManager, System.Windows.PresentationSource) 00b8eb7c 66052b6c System.Windows.Interop.HwndStylusInputProvider..ctor(System.Windows.Interop.HwndSource) 00b8ebcc 660519c6 System.Windows.Interop.HwndSource.Initialize(System.Windows.Interop.HwndSourceParameters) 00b8ec68 66051642 System.Windows.Interop.HwndSource..ctor(System.Windows.Interop.HwndSourceParameters) 00b8ecb4 64f81573 System.Windows.Window.CreateSourceWindow(Boolean) 00b8ed44 650437ae System.Windows.Window.CreateSourceWindowDuringShow() 00b8ed48 64f82b23 System.Windows.Window.SafeCreateWindowDuringShow() 00b8ed54 64f82a3b System.Windows.Window.ShowHelper(System.Object) 00b8ed78 64fd6a7c System.Windows.Window.Show() 00b8ed84 656d3209 System.Windows.Window.ShowDialog()

00b8edd4 07aa8402 MyNameSpace.MyClass.MyMethod()

0:000> ~9s eax=0000397e ebx=05137a0c ecx=0840e8e8 edx=77577174 esi=000006fc edi=05137a08 eip=77577174 esp=0840e84c ebp=0840e8c4 iopl=0 nv up ei pl nz ac po cy cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00000213 ntdll!KiFastSystemCallRet: 77577174 c3 ret

0:009> !clrstack OS Thread Id: 0x133c (9) Child SP IP Call Site 0840f248 77577174 [PrestubMethodFrame: 0840f248] MS.Win32.Penimc.UnsafeNativeMethods.GetPenEventMultiple(Int32, IntPtr[], IntPtr, Int32 ByRef, Int32 ByRef, Int32 ByRef, Int32 ByRef, Int32 ByRef, IntPtr ByRef) 0840f28c 66523055 System.Windows.Input.PenThreadWorker.ThreadProc() 0840f2d8 6793c9ff System.Threading.ThreadHelper.ThreadStart_Context(System.Object) 0840f2e4 67932367 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 0840f350 679322a6 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 0840f364 67932261 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object) 0840f37c 6793ca7c System.Threading.ThreadHelper.ThreadStart() 0840f4c8 685f2652 [GCFrame: 0840f4c8] 0840f6ac 685f2652 [DebuggerU2MCatchHandlerFrame: 0840f6ac]

I would appreciate any help.

Thanks in advance. Regards.

How to make TabControl a static object if created in Designer

$
0
0

Hey all,

I've created a TabControl in Designer (I dragged it to Grid from Toolbox). Now I need to make a Property that returns reference - that TabControl so I could do something with it from another window made in the same project. I need to make it static. But it says that TabControl I created isn't static. So how can I make a TabControl that was made in Designer static ? 

Thanks !


Knowledge: C, C++, C#, Java, Pawn

Viewing all 18858 articles
Browse latest View live


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