|
Try this i am sure this will help u.
1.In Visual Studio, click the Project menu, and select Add Existing Item. Find and select the image you want to add to your project.
2.In the Solution Explorer window, right-click the image file you just added to your project, and select Properties from the popup menu. The Properties tool window appears.
3.In the Properties window (see picture below), change the Build Action property to Embedded Resource.
4.Build the project. The image will be compiled into your project's assembly.
Load Image Resource
Be sure to include the following namespaces in your project:
using System.IO;
using System.Reflection;
To load the image resource programmatically, use the following code:
Assembly myAssembly = Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream( "MyNamespace.SubFolder.MyImage.bmp" );
Bitmap bmp = new Bitmap( myStream );
The trickiest part of loading an embedded resource is getting the correct path. A resource path takes this form:
<namespace>.<subfolders>.<image name>.<extension>
where:
namespace is the namespace for the project
subfolders is the folder path within the project, with each folder separated by a period instead of a slash
image name is the name of the image file
extension is the image file extension (for example, "bmp" or "jpg")
|
|
|
|
|
Hello,
What i am doing is, i am creating a Datatable based on values that user fills up in the form.
Further i am assigning that datatable to the WPF datagrid to display the Grid.
dgMatrix.ItemsSource = GetDataSource.DefaultView
Now, as the user edits the grid and presses the SAVE button under the grid, I would like to save all the rows of the Grid into a new table in the database.
Is there a way to loop through each row of the Grid and then inserting each record into the database??
In ASP.net i was using the following function:
'For Each row As GridViewRow In dgMatrix.Rows
'
' Dim checkbox As CheckBox = CType(row.FindControl("cbRows"), CheckBox)
' If checkbox.Checked Then
' Try
' Dim txtFromPorts As TextBox = CType(row.FindControl("txtPortsFrom"), TextBox)
' Dim txtToPorts As TextBox = CType(row.FindControl("txtPortsTo"), TextBox)
' Dim txtFType As TextBox = CType(row.FindControl("txtFareType"), TextBox)
' Dim txtFClass As TextBox = CType(row.FindControl("txtFareClass"), TextBox)
' Dim txtLowGAmt As TextBox = CType(row.FindControl("txtGrossAmtLow"), TextBox)
' Dim txtLowNAmt As TextBox = CType(row.FindControl("txtNettAmtLow"), TextBox)
' Dim txtHighGAmt As TextBox = CType(row.FindControl("txtGrossAmtHigh"), TextBox)
' Dim txtHighNAmt As TextBox = CType(row.FindControl("txtNettAmtHigh"), TextBox)
' Dim txtPeakGAmt As TextBox = CType(row.FindControl("txtGrossAmtPeak"), TextBox)
' Dim txtPeakNAmt As TextBox = CType(row.FindControl("txtNettAmtPeak"), TextBox)
' ' Dim dr As DataRow = dtNew.NewRow
' strFrom = txtFromPorts.Text
' strTo = txtToPorts.Text
' strFareType = txtFType.Text
' If txtFClass.Text.Trim <> "" Then
' strFareClass = txtFClass.Text
' End If
' If txtLowGAmt.Text <> "" Then
' strGrossLow = txtLowGAmt.Text
' End If
' If txtLowNAmt.Text <> "" Then
' strNettLow = txtLowNAmt.Text
' End If
' If txtHighGAmt.Text <> "" Then
' strGrossHigh = txtHighGAmt.Text
' End If
' If txtHighNAmt.Text <> "" Then
' strNettHigh = txtHighNAmt.Text
' End If
' If txtPeakGAmt.Text <> "" Then
' strGrossPeak = txtPeakGAmt.Text
' End If
' If txtPeakNAmt.Text <> "" Then
' strNettPeak = txtPeakNAmt.Text
' End If
' 'Check if the checkbox is checked.
' strSQL = "INSERT INTO FareInfo (" + _
' "FareId," + _
' "PortsFrom," + _
' "PortsTo," + _
' "FareType," + _
' "FareClass," + _
' "GrossAmtLow," + _
' "NettAmtLow," + _
' "GrossAmtHigh," + _
' "NettAmtHigh," + _
' "GrossAmtPeak," + _
' "NettAmtPeak" + _
' ") VALUES ("
' If (strFareId <> "") Then
' strSQL = strSQL + "'" + strFareId + "',"
' strSQL = strSQL + "'" + strFrom + "',"
' strSQL = strSQL + "'" + strTo + "',"
' strSQL = strSQL + "'" + strFareType + "',"
' strSQL = strSQL + "'" + strFareClass + "',"
' If strGrossLow <> "" Then
' strSQL = strSQL + " " & strGrossLow & " ,"
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettLow <> "" Then
' strSQL = strSQL + "" + strNettLow + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strGrossHigh <> "" Then
' strSQL = strSQL + "" + strGrossHigh + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettHigh <> "" Then
' strSQL = strSQL + "" + strNettHigh + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strGrossPeak <> "" Then
' strSQL = strSQL + "" + strGrossPeak + ","
' Else
' strSQL = strSQL + " " & "null" & " ,"
' End If
' If strNettPeak <> "" Then
' strSQL = strSQL + "" + strNettPeak + ""
' Else
' strSQL = strSQL + " " & "null" & " "
' End If
' strSQL = strSQL + ")"
' End If
' DBClass.ExecuteQuery(strSQL)
' gvMatrix.Visible = False
' 'Insert 1 row in Progress grid
' Catch ex As Exception
' End Try
' End If
'Next
Can someone suggest me the right way to do so in WPF. I would really appreciate that, Thanks.
|
|
|
|
|
I believe the idea is that updates to the grid automatically update the data source, and so you should iterate over that.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Thanks for reply Christian.This is what i have done,
dvMatrix = GetDataSource.DefaultView
dgMatrix.ItemsSource = dvMatrix
Datasource1 = GetDataSource()
So, I am assigning itemsource using GetDataSource method which returns me a datatable. I will store it in a public datatable variable(DataSource1).
So inside the btnSave_click event,
Dim dt As DataTable
Dim dr1 As DataRow
dt = Datasource1 'i am using the datatable- DataSource1
Dim jk = dt.Rows.Count
For Each dr1 In dt.Rows
strFrom = dr1("PortsFrom")
strTo = dr1("PortsTo")
....
next
Problem is, i am still getting original grid content not the modified content.
Is there something i need to do inside dgMatrix_RowEditEnding function to update the datasource??
|
|
|
|
|
Your datasource needs to be an observablecollection for this to work. Perhaps it's not.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Excellent,with observablecollection its working. Thanks a ton for guiding me!!!
|
|
|
|
|
Just because i thought it will help me in future. If we fetch data from some table in database, into a observable collection.
And then display that data in the grid.
When the user edits the grid, changes are reflected in observable collection, is there a quick way to commit those changes in the database as well??
|
|
|
|
|
I don't really know, to be honest. I've not done any database work with WPF yet, that is nothing to a SQL database, all to my own file formats. I would imagine you'd want to make an observablecollection of a class type, and write code in there to update the DB if data is changed, or new data added, but that could be old school thought, there may be something better built in.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
I have the same feeling,there must be a better way of doing it. Thanks for your help though!
|
|
|
|
|
Any time you add an item into an observable collection, or remove an item, the collection raises a CollectionChanged event. You can use this to identify records that have been added or deleted. If you are updating a record though, the collection won't help you because it doesn't monitor changes to items in the collection; it only monitors changes to the collection itself.
What you need to do, in this case, is have your model expose INotifyPropertyChanged, and then (whenever a property is changed), raise a change notification on the item itself. This[^] article gives a bit more detail about notifications.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
See - I knew there was a smarter answer....
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Hi
I have a startup form in my app. When this form loads the main form in the background is blurred out using a BitmapEffect and a timer. The timer is used to increment the blur radius in every timer tick, and then un-blur the screen again using another timer.
What I want to know is, is there a better way of gradually blurring the form in the background without using a timer each time?
Below is a sample of the code I'm using.
void blurTimer_Tick(object sender, EventArgs e)
{
if (blurTimerCount != 10)
{
BlurBitmapEffect blurEffect = new BlurBitmapEffect();
blurEffect.Radius = blurTimerCount;
blurEffect.KernelType = KernelType.Box;
mainWindow.BitmapEffect = blurEffect;
blurTimerCount++;
}
if (blurTimerCount == 10)
{
blurTimer.Stop();
}
}
|
|
|
|
|
Setup a storyboard somehow, and "animate" it?
I was thinking about trying that myself.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Etienne_123 wrote: blurEffect.Radius = blurTimerCount;
This looks like the property you could just animate in a timeline in XAML, to me.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
This is actually quite trivial. Here's a sample:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Window.BitmapEffect>
<BlurBitmapEffect x:Name="blurTarget" KernelType="Gaussian" Radius="0"/>
</Window.BitmapEffect>
<Window.Triggers>
<EventTrigger RoutedEvent="Window.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Duration="0: 0:10"
From="0.0"
Storyboard.TargetName="blurTarget"
Storyboard.TargetProperty="Radius"
To="40.0"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Window.Triggers>
<Grid>
<Button Content="This Is my button" />
</Grid>
</Window>
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks guys, I got it working.
I just declared 2 new storyboards in my xaml (one for blurring and another for unblurring), then I just used the following in the code behind to start the storyboards:
Storyboard storyBlur = this.FindResource("blurMainWindow") as Storyboard;
storyBlur.Begin();
|
|
|
|
|
I tried this:
<BlurEffect x:Name="blurTarget" Radius="12" KernelType="Gaussian" />
<Storyboard x:Key="AnimateUnblur">
<DoubleAnimation From="12" To="0" Duration="0:0:1"
Storyboard.TargetName="blurTarget"
Storyboard.TargetProperty="Radius" />
</Storyboard>
and then tried this:
BlurEffect blur = (BlurEffect)FindResource("blurTarget");
this.Effect = blur;
And it's throwing an exception because it can't find the resource "blurTarget".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
I'm using page navigation, with pack URI's specified like this:
Uri uri = new Uri(@"/DetailAssembly;component/Detail.xaml",UriKind.Relative);
frame.Navigate(uri); In the LoadCompleted handler, I see the following:
public void _DetailLoadCompleted(Object sender,NavigationEventArgs e)
{
} Somewhere along the line, someone removed the leading '/' character from the relative URI.
I know this is a picayune little detail, but does anyone know why they would do this? I thought maybe there was something I'm not understanding about URI's in WPF, but I can't find anything on MSDN or in my books. My basic conclusion is that it's just a bug. Can anyone offer any other explanation?
Software Zen: delete this;
|
|
|
|
|
Hi,
I am writing WPF custom control. My problem is I want to do some updations in the control when the control is being creted by copy paste( CTRL+C, CTRL+V) on the cider.
How can I track this event or attch an handler to this event.
Does ApplicationCommand.copy.... make any sense here.
Please help.
Thanks in Advance,
Vinod
|
|
|
|
|
You mean when it gets added to a form in the designer ? I'm not sure how you write event code in your control, for an event that fires in another program, but I suspect if it can be done, it will be an actual event that's called by the IDE, OR the constructor is called and you can write a block of code that detects if you're in the designer ( this can be done in Winforms, for sure )
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
You'll need to write a designer for your control. This is not trival.
You can search for WPF control designer for examples.
There is also documentation on MDSN.
modified 27-Feb-21 21:01pm.
|
|
|
|
|
Hi,
I am working on a WPF application. In this we will change the position of the components on the canvas. Every time we change the positions of the components on the canvas, we have to display a thumbnails of the canvas.
I have a procedure to create the images of the canvas.
http://blogs.msdn.com/saveenr/archive/2008/09/18/wpf-xaml-saving-a-window-or-canvas-as-a-png-bitmap.aspx
Now I have to display the images of the thumbnail as canvas dynamically as thumbnails.
If anyone have any idea to solve this please reply me.
Thanks in Advance
|
|
|
|
|
You might want to use a variation of this[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
In WPF, I can set Image with a photo, and can see when I load the page. However, if I want to set that through a code-behind, I cannot. Here is my code, do you find anything wrong in it that might cause this problem? I checked on compile time, and there is no problem in the location of myPhoto.png.
> string location = @"C:\myPhoto.png";
> Uri uri= new Uri(location,> UriKind.Relative);
> ImageSource imgSource = new BitmapImage(uri);
> Icons.Source = imgSource;
> Icons.Width = 10;
>Icons.Height = 10;
> Icons.Visibility = Visibility.Visible;
thanks,
|
|
|
|
|
Maybe try
C:/ myPhoto.png
Or
File://C:/myPhoto.png
The UriKind should be Absolute as well.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|