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

The time has come! Step up WPF Gurus! Your community needs heroes like you!

$
0
0

TechNet Gurus... we salute you!

You're awesome, and we know it!

Your knowledge uploads and nifty info nuggets are our life blood at TechNet Wiki.

Every awesome article that gets an award is just the start. We are building up the most sensational collection of gifts of knowledge from eminent community heavy weights and young guns alike. And we plan to promote you and your work wherever we can.

Reputations are being forged.

History is being made.

Generations will know your name.

Your children, grandchildren and great-grandchildren will marvel at your technical prowess.

And now, my mighty code warriors, cool consultants and platform specialists, now your chance is here again.

A new month of possibilities. Another chance to prove YOU are the ONE!

The mighty TechNet Guru medal winner for June!

Take up your mouse and keyboard!

Unleash your mighty words of wisdom and bask in the glory that we bestow upon you!

GO GO Gurus! Give, give, give!

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

Submit now : http://social.technet.microsoft.com/wiki/contents/articles/24692.technet-guru-contributions-for-june-2014.aspx

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.



Why I got False instread of True?

$
0
0

Hi

static void Main(string[] args)
        {
            double dbl = 1.234567890;
            decimal dec = 1.234567890M;
            float f = 1.234567890F;

            if (dbl.ToString() == dec.ToString())
                Console.WriteLine("True");
            else
                Console.WriteLine("False");

            if (f.ToString() == dec.ToString())
                Console.WriteLine("True");
            else
                Console.WriteLine("False");

            if (f.ToString() == dbl.ToString())
                Console.WriteLine("True");
            else
                Console.WriteLine("False");
        }

Why i got 3 False? Don't know why not True in this case

How to integrate skype in wpf application

$
0
0
hi sir, 
 
My requirement is to integrate Skype in wpf window. but i am unable to integrate it when i tried to integrate it. it opens in new window not in wpf window . My requirement is the video chat  tool to integrate in wpf window .can anyone help me  to find out this problem . i also tried to position the skype window  after launching in  the new window  with this sample code but i am unable to position with the code Can u give the complete code for positioning the window of skype 
 Process[] processes = Process.GetProcesses();
            foreach (var process in processes)
            {
                Console.WriteLine("Process Name: {0} ", process.ProcessName);

                if (process.ProcessName == "Skype")
                {
                    IntPtr handle = process.MainWindowHandle;
                    RECT rect;
                    var windowRec = GetWindowRect(handle, out rect);
                    // When I move a window to a different monitor it subtracts 16 from the Width and 38 from the Height, Not sure if this is on my system or others.
                    SetWindowPos(handle, (IntPtr)SpecialWindowHandles.HWND_TOP, 50, 0, 500, 200, SetWindowPosFlags.SWP_SHOWWINDOW);                 
                }
            }

Access trigger a method in Mainwindow from it's Child Usercontrol

$
0
0

Hi,

i am having a Mainwindow which has an UserContol as a child. where i need to pass a image from usercontrol to mainwindow and also trigger a method which will assign the image to the particular Canvas

Thank You

What is this operator in C# :: and how to use it?

$
0
0

Hi,

I am not sure if this word is operator or not but curious to know. Please explain

::

If it is an operator how to use it?

MediaElement Stops playing (.NET 4.0 + WPF)

$
0
0

Hi All

Having troubles to make MediaElement continue palying when the ViewModel it is in is not showing any more. (Though the Object is still in scope, not disposed).

I am using a ContentControl on my main window. First I show a VM which has a button (on whose click the Music Player VM should be displayed).

<ContentControl Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3"
            Content="{Binding CurrentViewModel, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

On Button Click - I set the binding CurrentViewModel to the VM of music player. That shows & works properly.

Problem happens when I set the Binding CurrentViewModel to some other (diff) VM screen but making sure the Music Player VM object is not disposed it is very much alive. The media element stops playing when its not the displayed VM.

What I want to achieve is opening many VM's at a time in ContentControl and even if the Music Player is not being shown, the medielement should continue playing.

Cam somebody help/guide? How do I make mediaelement play when its not being rendered on screen.

style doesn't work when applied to a buttons on a tabcontrol

$
0
0

Please, anyone can solve this issue?
I tried to apply a simple style at a couple of buttons on a tabcontol, but when I switch among the tab items the contents of buttons disappear. This is the code:


    <Window.Resources>
        <Style x:Key="myButton" >
            <Setter Property="Button.FontSize" Value="12"/>
            <Setter Property="Button.Background" Value="DarkGray"/>
            <Setter Property="Button.Foreground" Value="AliceBlue"/>
            <Setter Property="Button.Width" Value="150"/>
            <Setter Property="Button.Height" Value="100"/>
            <Setter Property="Button.Margin" Value="3"/>
        </Style>
        <Style x:Key="ButtonStyle1" BasedOn="{StaticResource myButton}">
            <Setter Property="Button.Content">
                <Setter.Value>
                    <StackPanel Orientation="Vertical">
                        <Image Height="32" Width="32" Source="some image" />
                        <TextBlock Text="ButtonStyle1" TextWrapping="Wrap" TextAlignment="Center"/>
                    </StackPanel>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="ButtonStyle2" BasedOn="{StaticResource myButton}">
            <Setter Property="Button.Content">
                <Setter.Value>
                    <StackPanel Orientation="Vertical">
                        <Image Height="32" Width="32" Source="some image" />
                        <TextBlock Text="ButtonStyle2" TextWrapping="Wrap" TextAlignment="Center"/>
                    </StackPanel>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <TabControl HorizontalAlignment="Left" Height="326" Margin="20" VerticalAlignment="Top" Width="652">
            <TabItem Header="TabItem1">
                <Grid Background="#FFE5E5E5">
                    <StackPanel Orientation="Horizontal" Margin="50">
                        <Button  Style="{StaticResource ButtonStyle1}" />
                        <Button  Style="{StaticResource ButtonStyle2}" />
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="TabItem2">
                <Grid Background="#FFE5E5E5">
                    <StackPanel Orientation="Horizontal" Margin="50">
                        <Button  Style="{StaticResource ButtonStyle1}"/>
                        <Button  Style="{StaticResource ButtonStyle2}" />
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="TabItem3">
                <Grid Background="#FFE5E5E5">
                    <StackPanel Orientation="Horizontal" Margin="50">
                        <Button  Style="{StaticResource ButtonStyle1}"/>
                        <Button  Style="{StaticResource ButtonStyle2}" />
                    </StackPanel>
                </Grid>
            </TabItem>
        </TabControl>
    </Grid>

Thank you in advance at who will help me!

Andrea

WPF Application crashing on startup on some computers but not all.

$
0
0

I have a .NET WPF application targeting the .NET 4 framework (previous versions of the same application targeted 3.5).  I'm not sure if the change in the framework targeting is related to this problem but I figured I'd point it out.


I am getting a crash when the application starts up, but only on some PC's.  On other PC's it works fine.  On any of these PC's previous versions of this same application worked fine.  The crash is due to an unhandled exception on the app startup.

 

Here is the stack trace of the exception:

Application: MyApp.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
Stack:
   at System.Signature.GetSignature(System.SignatureStruct ByRef, Void*, Int32, System.RuntimeFieldHandleInternal, System.IRuntimeMethodInfo, System.RuntimeType)
   at System.Reflection.RuntimePropertyInfo.get_Signature()
   at System.Reflection.RuntimePropertyInfo.get_PropertyType()
   at System.Reflection.CustomAttributeData..ctor(System.Reflection.RuntimeModule, System.Reflection.CustomAttributeRecord)
   at System.Reflection.CustomAttributeData.GetCustomAttributes(System.Reflection.RuntimeModule, Int32)
   at System.Reflection.CustomAttributeData.GetCustomAttributesInternal(System.Reflection.RuntimeAssembly)
   at System.Reflection.RuntimeAssembly.GetCustomAttributesData()
   at System.Reflection.CustomAttributeData.GetCustomAttributes(System.Reflection.Assembly)
   at System.Resources.ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(System.Reflection.Assembly, System.Resources.UltimateResourceFallbackLocation ByRef)
   at System.Resources.ResourceManager.CommonSatelliteAssemblyInit()
   at System.Resources.ResourceManager..ctor(System.String, System.Reflection.Assembly)
   at System.Windows.SplashScreen..ctor(System.Reflection.Assembly, System.String)
   at MyApp.App.Main()

--------

In addition to the exception above, which my app logs to event viewer, I also have another event that occurs at the same time, also in the application log.  The source is "Application Error" and it reads as follows:

 

Faulting application name: MyApp.exe, version: 2.4.1.0, time stamp: 0x4d278ccc
Faulting module name: KERNELBASE.dll, version: 6.1.7600.16385, time stamp: 0x4a5bdbdf
Exception code: 0xe0434352
Fault offset: 0x0000b727
Faulting process id: 0xe28
Faulting application start time: 0x01cbaec139ccd566
Faulting application path: C:\Program Files (x86)\My App Path\My App\MyApp.exe
Faulting module path: C:\Windows\syswow64\KERNELBASE.dll
Report Id: 77e811de-1ab4-11e0-a6cf-a4badbfae9cd

 

--------------------------

 

So while it appears that this is happening on the splash screen constructor, I am very confused because at this point I have removed the splash screen entirely from the app.  There is no splash screen configured.  And it's a FileNotFound exception, I don't know what file it's looking for.

 

Any help would be much appreciated.

 

Thanks,

Greg

 


Accessing WPF controls from a callback function.

$
0
0
<Window x:Name="MainWindow1" x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="384" Width="669.114" Loaded="OnLoaded" Icon="alarmclock.ico" Closing="OnClosing" ><Grid><GroupBox Header="Dashboard" HorizontalAlignment="Left" Height="130" Margin="10,10,0,0" VerticalAlignment="Top" Width="641"></GroupBox><Label x:Name="Label1" Content="Alarm Off" HorizontalAlignment="Left" Margin="10,317,0,0" VerticalAlignment="Top" Width="96"/></Grid></Window>

    public partial class MainWindow : Window
    {
        private static DataSet ds;
        private static DataTable alarms;

        static void alarmCallback1(IntPtr complretionArg,
                                               UInt32 timerLow, UInt32 timerHigh)
        {

            MessageBox.Show(ds.Tables["Alarms"].Rows[0][3].ToString());
            if (ds.Tables["Alarms"].Rows[0][3].ToString() == "25%")
            {
                waveOutSetVolume(IntPtr.Zero, 10000);
            }
            if (ds.Tables["Alarms"].Rows[0][3].ToString() == "50%")
            {
                waveOutSetVolume(IntPtr.Zero, 100000);
            }
            if (ds.Tables["Alarms"].Rows[0][3].ToString() == "75%")
            {
                waveOutSetVolume(IntPtr.Zero, 1000000000);
            }
            if (ds.Tables["Alarms"].Rows[0][3].ToString() == "100%")
            {
                waveOutSetVolume(IntPtr.Zero, 4294967295);
            }

            try
            {
                // Assign the selected file's path to  
                // the SoundPlayer object.  
                player.SoundLocation = ds.Tables["Alarms"].Rows[0][2].ToString();

                // Load the .wav file.
                player.Load();
                player.PlayLooping();

                alarmOn = true;
                //changeLabel.Content = "Alarm On";
            }
            catch (Exception ex)
            {
                string message = ex.Message.ToString();
                MessageBox.Show(message);
                Environment.Exit(1);
            } 
        }

In this case I want to set the text of Label1 from the alarmCallback1 callback function. alarmCallback1 is a callback for a waitable timer. It is executing on expiration of the waitable timer at which time I have to sound an alarm and change the value of Label1 to "Alarm On". Is there some way to do this with WPF?

I'm looking into a ManualResetEvent but I'm not sure if that's the answer yet.

I'm starting waitable timer like:

                    //Set a waitable timer for the due time
                    Thread thrAddAlarm = new Thread(() => threadsDelegate(TimeSpan.FromMinutes(dtCurSpan.TotalMinutes), alarmNum));
                    thrAddAlarm.Start();

so when the thread is released and the callback executes I would like to set the values in some WPF controls at that time.

Thank you.



Parse All DateTime Format

$
0
0
 

Hi
I 'm still with my difficulties as beginner  in C # .

I am currently builfing a reader Rss Feed .
When the user enters RSS URL, the RSS data are saved in a database . (DATE , HEADLINES , DESCRIPTION , LINK , SOURE RSS )

I have no problem to do that .. Everything is displayed correctly.
Since I have more 100 or 200 feeds , I had the idea to classify them according to the recent publication date .
 - When I recovered the value that is in the <pubDate> tags in the XML file , I try to convert it into a standard format and then to the TimeStamp before saving . and classification works well too.
Here is the code that works very well so far

   DateTime sdateValue = new DateTime();

                        string dateString = ladate[x - 1].InnerText;
                        // string dateoutput;
                        if (DateTime.TryParse(dateString, out sdateValue))
                        {

 var timestamp = ToUnixTimestamp(sdateValue);
                        }
                        else
                        {
                             MessageBox.Show("  Unable to parse '{0}'.", dateString);
                        }

The witness, this is what I thought I came across a few RSS that have  the following formats:
Wed, 26 Feb 2014 05:27:04 EST
2/27/2014 8:40:16 PM GMT
my code is unable to convert these dates.
I want a function that can convert all formats dates possible 
I am doing research I came across some code like this but it does work .

                        DateTime sdateValue = new DateTime();
                         CultureInfo culture = CultureInfo.CreateSpecificCulture("it-IT");
                         DateTimeFormatInfo myDtfi = new DateTimeFormatInfo();

                        
                        String[] myPatternsArray = myDtfi.GetAllDateTimePatterns();


                        string dateString = ladate[x - 1].InnerText;
                        
                        if (DateTime.TryParseExact(dateString, myPatternsArray, culture, DateTimeStyles.None, out sdateValue))
                        {
                        var timestamp = ToUnixTimestamp(sdateValue);

                        }
                        else
                        {
                          //  MessageBox.Show("  Unable to parse '{0}'.", dateString);
                        }

I hope that you can help me to solve it .

- Finally I would ask the same opportunity if there is also a function that would allow you to encode and display other alphabets in my database (eg JAPANESE , Chinese, RUSSIAN ...) 

Thank you in advance 


AS

Style not working properly for Label and TextBox

$
0
0

Hi,

I have the style like:-

 
<Style TargetType="Textbox">
  <Style.Trigger>
     <Trigger Property="IsEnabled" value="True">
           <Setter property="Foreground" value="Brown"/>
     </Trigger>
    <Trigger Property="IsEnabled" value="False">
           <Setter property="Foreground" value="Blue"/>
    </Trigger>
 </Style.Trigger>
</ Style>
 

Here everthing is working fine but when i give the "IsEnabled= false", then that particular trigger is not working.

This same case for the label also.

May i know where i am mistaking and how to make this work.
 
Thanks in advance.

NANDAKUMAR.T


WPF Mask in Mask

$
0
0

Hi!

I Need an easy function...

A WPF Mask with Title and so on...

In this Mask i will bring in a new mask (inside the Mask with the Title but without any title)

Have anyone an easy short Sample for me?

Best Regards

Bernd

how to upload image in Datagridtemplatecolumn & uploaded Image show in datagridtemplatecolumn at runtime using upload button (wpf C# use)?

$
0
0
<UserControl x:Class="design1.newuser"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Loaded="UserControl_Loaded">
    <Grid Height="610" Width="810">
        <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.Style>
                <Style>
                    
                    <Setter Property="Button.FontSize" Value="12" />
                    <Setter Property="Button.FontWeight" Value="Bold" />
                </Style>
            </DataGrid.Style>
            <DataGrid.Columns >
                <DataGridTemplateColumn  >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button  Content="upload" Click="btnUpload_Click" ></Button>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                <DataGridTemplateColumn Header="upload your picture"   >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Image Source="{Binding upload_your_picture}" Name="image2" Height="40" Width="60"/> 
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
            </DataGrid.Columns>
        </DataGrid>
        <TextBox Height="23" HorizontalAlignment="Left" Margin="536,26,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" />
    </Grid>
</UserControl>


 private void btnUpload_Click(object sender, RoutedEventArgs e)
        {
            var id1 = (DataRowView)dgvreg.SelectedItem;          
            
            string upload = Convert.ToString(id1.Row["upload_your_picture"].ToString());
            
            ImageClass imgs = new ImageClass();
            Context DB = new Context();
            OpenFileDialog OpenFileObj = new OpenFileDialog();
            OpenFileObj.ShowDialog();  
           
            upload= OpenFileObj.FileName;
            ImageSource imgsource = new BitmapImage(new Uri(upload));
          
        }

Show Correct Usercontrol based on Selection

$
0
0

Goal:
When you click one of the button from the usercontrol_menu the current and displayed usercontrol will be removed or invisible. A new usercontrol, based on the selection, will be displayed.

Problem:
How to change the usercontrol (Candy, computer, happy) after clicking the button from the usercontrol menu?

Information:
1.
- What approach is recommended? is it to remove and add a specific code in the xaml source?
- Another approach is to make the usercontrol to be visible or invisible inside of mainwindows (aaa).

2. You display one usercontrol (candy, computer, happy) at a time.

3.The usercontrol (candy, computer, happy) shall have same position.

<Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:menu="clr-namespace:menu;assembly=menu" x:Class="aaa.MainWindow"
        Title="MainWindow" Height="395" Width="763"><Grid><menu:UserControl1 HorizontalAlignment="Left" Margin="52,10,0,0" VerticalAlignment="Top"/></Grid></Window>


Prism 4.1 , Silverlight 5 with .Net 4.5.1 DelegateCommand Not working

$
0
0

http://stackoverflow.com/questions/24477864/prism-4-1-silverllight-5-and-net-4-5-1-delegatecommant-for-button-not-working

Problem is In Test Project I've a simple form in 1 Module and just a submit Button which I bind with DelegateCommand and it is not firing the command and button is not wroking

Please help


Map two coordinate system points in one

$
0
0

Hi.

Here is situation.

I have canvas on WPF. e.g. (0,0) -> (200,200)

And i have other coordinate system 2 e.g. (50,50) -> (300,300)

How can i map point from coordinate system 2 to canvas?

I mean if system 2 have point 125,125 (middle) on canvas it should appear 100,100 (also in middle)

Probably should have same behavior like CoordinateMapper in Microsoft.Kinect

Can someone give me some tips, how to map that point?

Thanks.

Binding event handlers for a webview in MVVM pattern for Windows 8.1 phone

$
0
0

Hello all,

In my Windows 8.1 phone XAML/C# based app, I am trying to bind NavigationCompleted event for a webview from my view model that I have used, but I am not able to get it.

Can anyone please give a small example of how to bind an event handler in a webview that is there in the view, from the corresponding view model?

Any help would be much appreciated.

Thanks,

Sreeram

Simulate Shift+F2 for Citrix Receiver Full screen mode

$
0
0
Hi,
 
I am trying to simulate Shift+F2 to enter Citrix Receiver full screen mode. I did try with On-screen Keyboard and everything worked correctly. However, when I simulated Shift+F2 (using InputSimulator library or SendKeys library) Citrix Receiver did not enter full screen mode. I did catch the simulation key-press (Shift+F2), it was the same result as pressing physical key or using On-screen Keyboard.
 
I am using WPF. Please tell me the how to enter full screen mode by simulate key-press or the way to config Citrix Receiver startup at full screen mode.
 
Many thanks


Expression Blend 2013 problem

$
0
0

I want to upgrade my project from VS 2010 to 2013 and .NET 4.5.1.

It is a desktop application with many WPF forms (over 200) and I have a big problem with Expression Blend 2013 performance.

It is impossible to work because it constantly freezes (especially when I first open it, at least 10') and has a very slow response time to anything I do (like click on the xaml panel).

My computer specifications:

CPU: i7 

RAM: 6 GB

Grafics Card: NVIDIA GeForce GTX 750 Ti  

Operating System: Windows 7 Professional

Please suggest.

Unloading an AppDomain that uses a .NET .DLL that displays a WPF dialog causes "CannotUnloadAppDomainException' exception, only on touchscreen computers.

$
0
0

We have an application that can hose external plugins via AppDomains.  If one of these plugins is utilizing a .NET dll that opens a WPF dialog window, the host application throws an 'CannotUnloadAppDomainException' exception ONLY on a computer with a touchscreen when it tries to unload the AppDomain.  I've been able to prevent a crash by catching the exception, but is there anything else I can do to clean things up properly?

Any ideas what would cause this issue specific to a touchscreen equipped machine?

Thanks,

Chris

Senior Software Engineer

Pitney Bowes Software


Viewing all 18858 articles
Browse latest View live


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