|
This might offer some ideas:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/7dcd018f-16aa-4870-8e47-c1b4ea31e574.htm
If PicDb is a separate data struture, maybe binding to a method and passing the name could work. In that case:
ms-help://MS.VSCC.v90/MS.MSDNQTR.v90.en/wpf_conceptual/html/5f55e71e-2182-42a0-88d1-700cc1427a7a.htm
|
|
|
|
|
If you don't want to go the whole MVVM route, a simple fix is to use a ValueConverter here. Consider the following sample converter code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace SampleWpfApplication
{
public class SimpleImageConverter : IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
Uri uri = new Uri(value.ToString(), UriKind.Absolute);
BitmapImage img = new BitmapImage(uri);
return img;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
} To use the converter, you add a reference to it in your Resources
section:<local:SimpleImageConverter x:Key="MyConverter" /> Finally, you bind to it using:<Image Source="{Binding ImageItem, Converter={StaticResource MyConverter}}" /> It's that simple.
"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
|
|
|
|
|
If you see Pete's post, you could just read your XML file in the converter and get the image name for the passed in header string. This will avoid you having to bother about multiple datasources in XAML.
If you still want to use XMLDataProvider, you could use a MultiValueConverter. Passing in the XMLDataProvider and the Header string to the converter.
|
|
|
|
|
Helped me a lot!! Thanks!
|
|
|
|
|
If I insert the following bit of XAML:
<TextBlock Background="AliceBlue" DataContext="{Binding FOO}"<br />
Text="{Binding StringFormat='Selected: {0:N0}', Path=BAR}"/ >
there is nothing in my project called FOO and certainly nothing called BAR - yet there is no error - nothing in output - the whole thing is just ignored.
Why does WPF ignore stuff?
|
|
|
|
|
I'm surprised that you haven't seen something in your Output window. What you might want to do, is use the diagnostics attached property:
<TextBlock Background="AliceBlue" DataContext="{Binding FOO, diag:PresentationTraceSources.TraceLevel=High}"
Text="{Binding StringFormat='Selected: {0:N0}',
Path=BAR, diag:PresentationTraceSources.TraceLevel=High}"/ > To add this in, you need to map to the diagnostics namespace:
xmlns:diag="clr-namespace:System.Diagnostics;assembly=WindowsBase" This feature was introduced in .NET 3.5.
"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, it appears I was missing
DataContext="{Binding RelativeSource={RelativeSource self}}
at the top of the tree but why that should mean WPF just ignores stuff is beyond me. Still, it only wasted a few hours - it's a good job there is no swear jar here.
|
|
|
|
|
It's ignored by design. If the binding path doesn't exist then
it is quietly ignored. If the result is nothing to render, then
you're not going to see anything
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for the info.
I am sure that decision made sense to somebody - I have just spent ages messing around with my layout wondering why on earth a textblock wasn't showing - I mean everything compiled, there was no output messages so it had to be layout right? I will know better next time I suppose.
|
|
|
|
|
RugbyLeague wrote: I have just spent ages messing around with my layout wondering why on earth a textblock wasn't showing
Simply putting some static text like Text="Test" would have immediately shown
whether it was a layout or a binding problem...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That's the first thing I did - it appeared as expected - but I refused to believe it
|
|
|
|
|
Hi,
I am facing problem with using .XAP file in ASP.Net Website. I have written the following code to use .XAP in .Aspx page
<form id="form1" runat="server">
<div style="height:100%; background-color:#282828;" align="right">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="1%"></td>
</tr>
<tr>
<td width="1%">
<div style="height:100%; background-color:#282828;" align="right">--%>
<asp:Silverlight ID="Xaml1" runat="server" Source="~/ClientBin/SilverlightApplication.xap" MinimumVersion="2.0.31005.0" Width="100%" Height="100%" />
</div>
</td>
</tr>
<table>
If i write like that is only assigned to particular row but i want it for whole page. If I write <asp:silverlight> control after form tag then the silverlight content is assigned above the table and the table data seperated from silverlight content.
Please see the below link to drag and drop videos but that drag and drop videos is not working outside that row only within that row.
http://219.91.199.132/silverl/home.aspx
Can you please guide me how to user .XAP file to whole aspx page.
Thanks in Advance
Pavani
|
|
|
|
|
pavanip wrote: Can you please guide me how to user .XAP file to whole aspx page.
Do you want the Silverlight plugin to take up the entire browser window or
a cell in an HTML table?
Regardless, this isn't really a Silverlight question - you may get better response
on the Web Development board for HTML questions.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi
Are there any code sample for playing a rtsp or udp stream. I have live555 rtsp streaming server setup in my pc and like to play the stream using a wpf code sample using vs2008.
Will this support. How can I do this.
Please help
|
|
|
|
|
Hi,
I use adorners to move elements in a canvas but I want that those elements stay in the canvas bounderies. So when I drag an element over one of the bounderies, it should stay against that boundery and not cross it.
Now I only check the top and left bounderies with the Canvas.GetLeft and Canvas.GetTop. The width and height of the canvas is variable. Anybody has an idea how I can prevent the elements to cross the right and bottom bounderies?
Thx
|
|
|
|
|
Have you tried ClipToBounds[^] ?
How are you implementing the drag/drop ?
|
|
|
|
|
I hadn't tried it before but ClipToBounds doesn't work.
When I add a new UIElement (like an image) to the Canvas, I adorn it. That adorner adds a Thumb to each side of the UIElement and that thumbs handles the drag function.
private void HandleMove(object sender, DragDeltaEventArgs args)
{
if (StanagCanvas.GetLeft(this.AdornedElement) + args.HorizontalChange < 0)
{
StanagCanvas.SetLeft(this.AdornedElement, 0);
}
else if (StanagCanvas.GetRight(this.AdornedElement) - args.HorizontalChange < 0)
{
StanagCanvas.SetRight(this.AdornedElement, 0);
}
else
{
StanagCanvas.SetLeft(this.AdornedElement, StanagCanvas.GetLeft(this.AdornedElement) + args.HorizontalChange);
}
if (StanagCanvas.GetTop(this.AdornedElement) + args.VerticalChange < 0)
{
StanagCanvas.SetTop(this.AdornedElement, 0);
}
else if (StanagCanvas.GetBottom(this.AdornedElement) - args.VerticalChange < 0)
{
StanagCanvas.SetBottom(this.AdornedElement, 0);
}
else
{
StanagCanvas.SetTop(this.AdornedElement, StanagCanvas.GetTop(this.AdornedElement) + args.VerticalChange);
}
}
(StanagCanvas derives from Canvas)
Offcourse the Right and Bottom properties don't work because I allready use the Left and Top properties. The element doesn't cross the left and top boundery of the canvas.
I hope this is enough information.
|
|
|
|
|
You could do it without the Right/Top properties. Something like,
else if ( (StanagCanvas.GetLeft(this.AdornedElement) + this.AdornedElement.Width + args.HorizontalChange) > yourCanvas.Width )
{
StanagCanvas.SetLeft(this.AdornedElement, yourCanvas.Width - this.AdornedElement.Width);
}
|
|
|
|
|
I tried that already. The problem with that is that I don't have a reference to the canvas so I can't get the width of it. Or am I totally wrong (It is weekend now for me so I can't recheck it but in a few days my mind is clear again and I can get a fresh start)
That adorner class (derives from Adorner like you know) is separated from my canvas class. I only call it when initializing a new UIElement on the canvas to adorn that element (and it stays adorned until I close the program or the UIElement is deleted). I guess that after I have added the adorner, that adorner only knows his element (this.AdornedElement) and nothing else. The actions I take from then with that adorner, can only affect Attached Properties (Like SetLeft, ... + I have made some extra attached properties in my Canvas class).
I can be totally wrong. If you want to know, I'm only programming for a few months without a proper eduction for it (I had programming on school but only basics). I'm learning it all myself (C# and WPF) and I need to make program for a company where I'm kind of an intern (1 year internship in a foreign country after getting my degree to get some experience before going to work in my own country).
Hope you can say that I'm wrong and it is that simple (but I missed something)
|
|
|
|
|
Pauwels Bart wrote: private void HandleMove(object sender, DragDeltaEventArgs args)
Who is the sender ? Is it the element in canvas ? If yes, you can do something like this,
FrameworkElement parent = ((sender as FrameworkElement).Parent as FrameworkElement;
EDIT: forgot to mention, you can then get the Width parent.Width
modified on Thursday, April 2, 2009 2:15 PM
|
|
|
|
|
That looks like a good answer
I have tried to call the parent with the sender but that didn't work. That was probably because I didn't parse it as a FrameworkElement or something like that.
I wouldn't know what to do if this site and forum didn't exists. Thx very much for the help.
I will try it and let you know if it worked!
|
|
|
|
|
Ok, the sender was not the element in the canvas but the thumb. Luckely I can get the element with "this.AdornedElement" (standard build-in adorner function to get the adorned element).
So, the solution was:
private void HandleMove(object sender, DragDeltaEventArgs args)
{
FrameworkElement element = this.AdornedElement as FrameworkElement;
StanagCanvas stanagCanvas = element.Parent as StanagCanvas;
if (StanagCanvas.GetLeft(element) + args.HorizontalChange < 0)
{
StanagCanvas.SetLeft(element, 0);
}
else if (StanagCanvas.GetLeft(element) + element.Width + args.HorizontalChange > stanagCanvas.Width)
{
StanagCanvas.SetLeft(element, stanagCanvas.Width - element.Width);
}
else
{
StanagCanvas.SetLeft(element, StanagCanvas.GetLeft(element) + args.HorizontalChange);
}
if (StanagCanvas.GetTop(element) + args.VerticalChange < 0)
{
StanagCanvas.SetTop(element, 0);
}
else if (StanagCanvas.GetTop(element) + element.Height + args.VerticalChange > stanagCanvas.Height)
{
StanagCanvas.SetBottom(element, stanagCanvas.Height - element.Height);
}
else
{
StanagCanvas.SetTop(element, StanagCanvas.GetTop(element) + args.VerticalChange);
}
}
I just made it to difficult and overlooked this simple sollution! Now the element stays within the bounderies of the canvas.
thx ABitSmart
|
|
|
|
|
That's great
Looking at your code, when it crosses the bottom boundary, you are setting the Bottom. Shouldn't it be SetTop ?
|
|
|
|
|
How could I have missed that!
|
|
|
|
|
Any insight for a small civil engineering program.
It will have 4 forms(excluding open/close dialog boxes) and will run in C#:
Main - menubar, tabstrip, Datagrid and a couple buttons
Chart Form - Graphics form to display a generated flow chart
Project form - basically a glorified dialog box for project info
Report Form - basically just a .doc file holder
If I go the WPF route I would like to produce my own style (kinda like Vista but not so heavy).
I don't have much experience with WPF besides tutorials and articles and I just want some personal experiences to help me make an informed decision.
|
|
|
|