|
|
Mohammad Dayyan wrote: How can we change the Window Location in WPF with C# code ?
Set its Left and Top properties.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hello,
So far i have posted my little problem on several forums, some help but resolution to my problem. On with the question: I have a program, i want the user to be able to print any size from the print dialog form under preferences when they choose to select 8x11 etc and it will print the picture that you see on the image viewer. So far my printing is not working, it only prints the size of the imageviewer which is small but i want the user to select whatever size they want and whatever or how many copies they want it. I have the code below including the XAML, please helpa
Thank you in advance:
code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Windows.Forms;
namespace ImageViewer
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
try
{
OpenFileDialog dlg = new OpenFileDialog();
dlg.InitialDirectory = "c:\\";
dlg.Filter = "Image files (*.jpg)|*.jpg|(*.bmp)|*.bmp|All Files (*.*)|*.*";
dlg.RestoreDirectory = true;
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string selectedFileName = dlg.FileName;
FileNameLabel.Content = selectedFileName;
BitmapImage bitmap = new BitmapImage();
bitmap.BeginInit();
bitmap.UriSource = new Uri(selectedFileName);
bitmap.EndInit();
ImageViewer1.Source = new BitmapImage(new Uri(selectedFileName, UriKind.Absolute));
}
}
catch (Exception)
{
}
}
private void btnclose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
private void btnprint_Click(object sender, RoutedEventArgs e)
{
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
Size pageSize = new Size();
// sizing of the element.
ImageViewer1.Measure(pageSize);
dlg.PrintVisual(ImageViewer1, Title);
}
}
}
}
XAML:
<Window x:Class="ImageViewer.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="351" Width="486">
<Grid Height="310" Width="438">
<Button Margin="0,12,13,0" Name="BrowseButton" Click="BrowseButton_Click" HorizontalAlignment="Right" Width="102" Height="43" VerticalAlignment="Top">Browse</Button>
<Label Margin="86,0,13,19" Height="25" Name="FileNameLabel" VerticalAlignment="Bottom" />
<Label Margin="14.5,0,0,19" Height="23" Name="Label1" HorizontalAlignment="Left" VerticalAlignment="Bottom" Width="70.15">Current File:</Label>
<Image Margin="14.5,12,130,63" Name="ImageViewer1" Stretch="Fill" />
<Button HorizontalAlignment="Right" Margin="0,149,13,118" Name="btnprint" Width="102" Click="btnprint_Click">Print</Button>
<Button Height="41" HorizontalAlignment="Right" Margin="0,0,13,63" Name="btnclose" VerticalAlignment="Bottom" Width="102" Click="btnclose_Click">Close</Button>
<RadioButton HorizontalAlignment="Right" Margin="0,86,-5,0" Name="rdb4by6" Width="120" Height="15" VerticalAlignment="Top">4x6</RadioButton>
<RadioButton Height="16" HorizontalAlignment="Right" Margin="0,105,-5,0" Name="rdb5b7" VerticalAlignment="Top" Width="120">5x7</RadioButton>
<RadioButton Height="16" HorizontalAlignment="Right" Margin="0,126,-5,0" Name="rdb8x11" VerticalAlignment="Top" Width="120">8x11</RadioButton>
<Label Height="28" HorizontalAlignment="Right" Margin="0,54,-5,0" Name="label2" VerticalAlignment="Top" Width="120">Select Print Size</Label>
</Grid>
</Window>
|
|
|
|
|
hellow friends this is
<big>NAVINKUMAR:rolleyes: </big> from Coimbatore i am doing my final year project in using SILVERLIGHT i am new to this technology so some one help me to understand SILVERLIGHT to do my project
HELP ME ! !
|
|
|
|
|
|
I am almost thinking about WPF but from what I have seen so far (very shallow only) it seems to be all about binding. I hate binding, one of the first utilities I wrote was a BindForm which takes a datarow and a form and loops through the controls and containers on a form looking for control names matching the columns of the datarow and binding them. That was years ago and have hardly looked at binding since.
So all my dialog forms take the same steps
populate the combos
Get the datarow
call BondForm(this, drData)
Can this be done in WPF?
Is it reasonable to do this or is it defeating the purpose of WPF?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
While you could do this, you really are defeating the purpose of binding in WPF here. It's a whole different beast to what you got with WinForms and ASP.NET - it's far more powerful. Here[^], I demonstrate binding in ASP.NET, versus WPF to demonstrate binding at a very basic level. If you follow my blog links, I talk about binding in more detail.
|
|
|
|
|
Pete O'Hanlon wrote: you really are defeating the purpose of binding in WPF
Yeah, that's what I thought, I must admit I'm all about the data, and battleshit gray screens are just fine by me. Ah well, every thing changes I guess.
If I pursue this, at least there seems to be plenty of quality resource here, thanks
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
To be fair though, battleshit gray doesn't cut it any more ... at least from a users point of view.
|
|
|
|
|
Jammer wrote: doesn't cut it any more
true, I had a junior dev go through an app and prettify it by adding some colours, the users thought it was a MUCH better app, no change in functionality just added some color. I dunno whats the world coming to when a splash of color defines the quality of the app.
Ah yes I almost forgot, bah humbug, after all it is the season.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
hehe ... I see the same thing happening with apps I'm currently working on.
Most end users aren't that passionate about how the app works, just so long as it makes them feel they are in an episode of Star Trek they're happy ...
I'm also happy to oblige!
|
|
|
|
|
After reading your article it seems you should end up with 2 resource type in different places.
1 the dynamic resource of the grid that belongs on the form b/c of it's binding to the data
2 the styles and pretties that reside in a resource (think CSS) that give the app consistency.
I guess it is off to Josh's article to get the details.
Thanks Pete, still not convinced it is valid for LOB apps but as Jammer said the users are starting to expect this level of pretty in their apps.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Have a read through some of Karl's articles on using WPF for LOB apps. They should help to convince you.
|
|
|
|
|
Yeah, started in on the first one, I think I will need to commit to working through them to get involved. Nice that they are focused on LOB stuff.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I can only echo Petes points.
WPF is definitely LOB ready. It's a beast that needs taming in a lot of ways but its so the way forward.
|
|
|
|
|
Hi
How can I get the name of a control ie textblock which is defined in a datatemplate in the xaml when i am in the code page?
Koos
|
|
|
|
|
You give a control a name normally by using x:Name="myControlName" in the control. This control is then available in the Code Behind.
|
|
|
|
|
Hey guys, I read a couple of the articles on here as well as the MSDN Sample for this task however I seem to be stuck; was hoping you guys could help me.
The following is my code, and although the items appear in the list perfectly, the ExpanderHeader appears with no text despite my text binding and I haven't the foggiest idea what I'm doing wrong.
Any help would be greatly appreciated!
<CollectionViewSource x:Key='mrpSource'>
<CollectionViewSource.GroupDescriptions>
<d:PropertyGroupDescription PropertyName="Vendor" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<ListView BorderThickness="0" ItemsSource="{Binding Source={StaticResource mrpSource}}" Margin="15,0,25.221,-520" Name="lvMRP" VerticalAlignment="Bottom" Height="494">
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Margin" Value="0,0,0,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander IsExpanded="False" BorderBrush="SlateGray" BorderThickness="0,0,0,1">
<Expander.Background>
<RadialGradientBrush>
<RadialGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform ScaleX="1.702" ScaleY="2.243"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="-0.368" Y="-0.152"/>
</TransformGroup>
</RadialGradientBrush.RelativeTransform>
<GradientStop Color="Gainsboro" Offset="0"/>
<GradientStop Color="Cornsilk" Offset="1"/>
</RadialGradientBrush>
</Expander.Background>
<Expander.Header>
<DockPanel>
<TextBlock FontWeight="Bold" Text="{Binding Path=Vendor}" Margin="5,0,0,0"/>
</DockPanel>
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=CompanyPartNumber}" Width="310" HeaderContainerStyle="{StaticResource colHeaderStyle}">NRC/Jaro Stock#</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=VendorPartNumber}" Width="310" HeaderContainerStyle="{StaticResource colHeaderStyle}">Vendor Stock#</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=CustomerPartNumber}" Width="310" HeaderContainerStyle="{StaticResource colHeaderStyle}">Customer Stock#</GridViewColumn>
</GridView>
</ListView.View>
<ListView.BitmapEffect>
<DropShadowBitmapEffect />
</ListView.BitmapEffect>
</ListView>
Code Behind:
((CollectionViewSource)this.Resources["mrpSource"]).Source = dt_MRPTEST.DefaultView
|
|
|
|
|
Check the output window for any data binding errors. Install Mole and examine the DataContext of the Expander.Header, I often find it useful to add a keypress handler that calls Debugger.Break() when the pause key is pressed.
Some tips on debugging bindings are here.
|
|
|
|
|
Thanks for the tips...it turned out that the grouping passes the grouped data as "Name" rather than it's actual path name so all I had to do was change my binding from "Vendor" to "Name" in the text binding...guess it's just one of those oddities of programming...lol.
Thank you!
|
|
|
|
|
Hi everyone. I might be missing something obvious, but after I run a simple WPF storyboard to animate an object's width, I am no longer able to change the width manually. I have created the simple example below to demonstrate my point. The width change done by the first button works before you animate with the second button, but not after.
What am I missing here? How can I "unfreeze" my width property so I can set it again?
XAML:
<Canvas>
<Button Click="Button_Click">
Set width to 100
</Button>
<Button Canvas.Top="30"
Animate width to 250
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="RedRectangle" Storyboard.TargetProperty="Width" To="250" Duration="0:0:1" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Button.Triggers>
</Button>
<Rectangle Name="RedRectangle" Width="25" Height="25" Canvas.Top="70" Fill="Red" Stroke="Black" />
</Canvas>
C# code behind:
private void Button_Click(object sender, RoutedEventArgs e)
{
RedRectangle.Width = 100;
}
Thanks in advance
Josh Fischer
|
|
|
|
|
Found the answer to my own question: FillBehavior="Stop"
http://msdn.microsoft.com/en-us/library/aa970493.aspx
Josh Fischer
modified on Wednesday, December 10, 2008 10:23 AM
|
|
|
|
|
|
[WPF 3.5 SP1] is there any way to place a DependencyProperty in a base class so that if you have a set of usercontrols (with the same base) and each of those controls acting as a Routed Template and you had a for instance that you were binding a Title DependencyProperty to...
Templates being: XceedSubControl_3D
XceedSubControl_Standard
Since you have to have specify [typeof(XceedSubControl)] when the DependencyProperty is registered...and each of your templates have a different name how would you go about this? The DependencyProperty itself compiles fine but binding fails.
public class SubControlBase : UserControl { public static DependencyProperty TitleProperty = DependencyProperty.Register( "Title", typeof(String), typeof(XceedSubControl),
Thoughts or insights would be appreciated.
|
|
|
|
|
hi evrybody
i try to do task by WPF for trying the work with WPF enviroment
i try to add combobox in gridview but i dont know how can i bind or fill combobox in xaml
i wrote this but not enough
<ListView Width="Auto" ItemsSource="{Binding}" Height="Auto" IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn Header="Gender ID" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate >
<TextBox Margin="0,0,0,0" Text="{Binding Path=GenderID}" Width="100"></TextBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Gender Type" Width="120">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="Combo_Type" ItemsSource="{Binding Source={}" DisplayMemberPath="{Binding Path=GenderType}" Width="100"></ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
MD_NADA
|
|
|
|