|
For simplicity I have a 6 color cube (Every side has different color) and viewing with a camera. I would like to show same cube from opposite angle with diffrent camera. Both views are visible at the same time. First view works fine but when I want to add the cube in second view where different camera is installed, I get the error that the cube is already added to another view (which is true). I am unable to add one object to 2 views. Any idea how this can be done in WPF? Your help will be very much appreciated.
Best regards
Agha Khan

|
|
|
|
|
Guys,
I'm just picking up silverlight and Ria services, and must admit I'm a little frusterated. I have a working example of querying via ria services and binding to complex controls such as data grids, but if I try to use that same logic on something like a textblock, I get no love. I assume it's the asyncrhonus nature of the call, but every single example I find uses a darn data grid. Here is what I'm doing:
code behind:
SellerDomainContext domainContext = new SellerDomainContext();
SellerGrid.ItemsSource = domainContext.Sellers;
FirstName.DataContext = domainContext.Sellers;
LastName.DataContext = domainContext.Sellers;
domainContext.Load(domainContext.GetSellerByUsernameQuery("joe_seller"));
xaml:
<TextBox HorizontalAlignment="Left" Margin="8,8,0,19" Width="212" x:Name="FirstName" Text="{Binding TimeOfDay, Mode=OneWay}" />
<TextBox HorizontalAlignment="Left" Margin="8,8,0,19" Width="212" x:Name="LastName" Text="{Binding LastName, Mode=OneWay}" />
<data:DataGrid x:Name="SellerGrid"></data:DataGrid>
As I said, the grid works fine, the first and last name text blocks do not. Any links to articles or code snippets to instruct me on how to do simple data binding to objects such as a text block via ria services would be much appreciated!
Thanks again,
Ryan
|
|
|
|
|
In the current RIA services, DomainContext queries ALWAYS return
a collection of entities, not a single entity.
A collection will not have the "LastName" property on it...
that's a property of your entity class (I'd assume )
First, if you haven't already, upgrade to the latest WCF RIA
services (here: WCF RIA Services[^])
Then your code behind could be changed to something like this:
using System.Linq;
...
SellerDomainContext domainContext = new SellerDomainContext();
domainContext.Load(domainContext.GetSellerByUsernameQuery("joe_seller"), getSellerByUsernameLoadOp_Completed, null);
...
void getSellerByUsernameLoadOp_Completed(LoadOperation loadOperation)
{
if (loadOperation.HasError)
{
loadOperation.MarkErrorAsHandled();
}
else
{
SellerGrid.ItemsSource = loadOperation.Entities;
FirstName.DataContext = loadOperation.Entities.FirstOrDefault();
LastName.DataContext = loadOperation.Entities.FirstOrDefault();
}
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Worked perfectly, thanks Mark.
|
|
|
|
|
I'm trying to speed up the initial loading/busywork of the my Silverlight app. Right now once the Silverlight app is loaded on the client it makes an async call to the server to get data for its dropdown fields. I'd like to cut out this round trip.
Is there any way I can load the data from the DB and send it to the client with the initial request for the Silverlight app?
|
|
|
|
|
thrakazog wrote: Is there any way I can load the data from the DB and send it to the client with the initial request for the Silverlight app?
You can't do it from your Silverlight app because until the
Silverlight app is downloaded and running, none of your
Silverlight code runs.
You can, however, break your Silverlight app into parts so
the initial part is small so it downloads faster:
How to: Load Assemblies On Demand[^]
Also, searching on "silverlight application load time" or
"silverlight load on demand" yields many articles like these:
Silverlight how to: On-demand assembly deployment[^]
Cool Silverlight Trick #3 [^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: You can't do it from your Silverlight app because until the
Silverlight app is downloaded and running, none of your
Silverlight code runs.
I understand that Silverlight app itself can't do this. I was hoping there might be a way to send a resource down with the Silverlight app that it could have waiting for it once it started running. Kinda bundle the 2 things together.
...doesn't seem to be an option.
|
|
|
|
|
thrakazog wrote: I was hoping there might be a way to send a resource down with the Silverlight app that it could have waiting for it once it started running.
If it's a static resource, you can bundle it in the app's XAP file.
If it's dynamic data, you could certainly add stuff to the xap file before
it gets requested, but how would you initiate that on the server? You'd
have to do that from the hosting webpage...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
To get Rounded edge Listbox i searched for samples and finally get that.Here my code.
In XAML:
<ListBox Margin="22,122,27,126" Style ="{DynamicResource RoundedBox}" Name="listBox1" Background="DarkSeaGreen" Foreground="Yellow" SelectionChanged="listBox1_SelectionChanged" >
in ResourceDicationary WPF.XAML
<Style x:Key="RoundedBox" TargetType="{x:Type ListBox}">
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Padding" Value="0,0,1,1"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Border CornerRadius="5,5,5,5" BorderThickness="1,1,1,1" RenderTransformOrigin="0.5,0.5" x:Name="border" BorderBrush="#FFFFFFFF">
<Border.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1" ScaleY="1"/>
<SkewTransform AngleX="0" AngleY="0"/>
<RotateTransform Angle="0"/>
<TranslateTransform X="0" Y="0"/>
</TransformGroup>
</Border.RenderTransform>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Finally i got the rounded edge but..the background colr has gone and now it is transparent.
What im missing?Im new to WPF.Pls help me.
Before inclcuidn resourcedictionary in XAML,it shows the clor.After i inserted the line
Style ="{DynamicResource RoundedBox}" ..the colrs goes but i get rounded edge listbox.
|
|
|
|
|
Maybe set the Border's Background property...
<Border Background="{TemplateBinding Background}" CornerRadius="5,5,5,5" BorderThickness="1,1,1,1" RenderTransformOrigin="0.5,0.5" x:Name="border" BorderBrush="#FFFFFFFF">
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Yes i got that.after adding border background i get that colr.
I cannot get text display.
Im pressing button,then text display in listbox.But it didnot display.
private void button2_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("2nd Button form C#");
string str = "C#item";
listBox1.Items.Add(str);
}
|
|
|
|
|
shanmugarajaa wrote: Im pressing button,then text display in listbox.But it didnot display.
Your template doesn't provide an items host.
There's an example of a rounded listbox in the documentation
(scroll down to see the different samples):
ItemsControl.ItemsPanel Property[^]
There's also a complete sample template for listbox and many
other controls...
ListBox ControlTemplate Example[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am wondering if anyone can point me to some code (or DLL) to build a native OpenFileDialog and FolderBrowserDialog in wpf / xaml, rather than using the System.Windows.Forms controls?
We have now replaced the Forms MessageBox with a native WPF taskdialog, which looks much better and behaves more consistently. I would like to do the same for OpenFileDialog and FolderBrowserDialog.
Thanks,
Tim
|
|
|
|
|
WPF has a OpenFileDialog class in the Microsoft.Win32 namespace.
For Folder Browser dialog, see my blog[^]
I thought Pete O'Hanlon was working on a WPF version at one time
It's definitely a project to make a WPF version to replace the OS
dialogs...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have been working on one - it's something that I keep coming back to when I have some free time. It's a hell of a complex beast though, as I'm trying to make it completely skinnable.
"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
|
|
|
|
|
I've only just been able to get back to this question - sorry for the long delay in responding. I guess it looks like this is a complex issue - I'll keep wrapping the System.Windows.Forms controls for the time being, and look out for further developments on this question. Hopefully Microsoft might build something into a future version...
Thanks,
Tim
|
|
|
|
|
I've got a 3rd party control:
class Foo : SomeWPFControl, INotifyPropertyChanged
{
public DateTime Start { get; }
public event PropertyChangedEventHandler PropertyChanged;
}
I slap this control on my view. Then I code up a little ViewModel. All is good.
I need to do work in my ViewModel when the control's Start property changes. How do you recommend doing this?
Attempt #1: I tried creating a DateTime property in my view model, then binding the control's .Start property to my property in the ViewModel, but that didn't work because "Start is a read-only property". Fail.
Attempt #2: I can listen to control.PropertyChanged inside my view, and when it fires, call some function on my ViewModel. But that doesn't seem very MVVMish. Fail?
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Have you tried, in the binding, specifying "Mode=OneWayToSource"?
If that doesn't work, then if I'm interpreting this correctly, #2 is probably the way to go.
|
|
|
|
|
Yeah, I still get a compiler error when specifying Mode = OneWayToSource.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Strange... Might not be set up properly as a DependencyProperty. #2 might be your only option, unfortunately.
|
|
|
|
|
There is a DependencyProperty on the class:
public Foo
{
public static DependencyProperty StartDateProperty;
public DateTime StartDate
{
get { ... }
}
}
The only way to change the StartDate is by clicking a button in the 3rd party control.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Hmm, strange way of setting it up...
I mean, you could bind another control to that value, but you can't bind the "StartDate" to a CLR object.
Yeah, I don't see a solution here other than hooking PropertyChanged.
|
|
|
|
|
Alright, well that's a legitimate answer, too. Thanks.
I'm mostly a newb when it comes to WPF, and definitely a newb when it comes to MVVM. I just wanted to be sure I wasn't doing things improperly. If this is the only way to make this work, alrighty.
Religiously blogging on the intarwebs since the early 21st century: Kineti L'Tziyon
Judah Himango
|
|
|
|
|
Yeah, it's not ideal, but you do what you have to do, right?
|
|
|
|
|
Is the Start property in the control readonly? What is the mechanism for updating this property?
"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
|
|
|
|