|
You should be able to do this by applying a style to the DataGridColumnHeader. Off the top of my head, the following should do it:
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding}" HorizontalAlignment="Right" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
|
Hi and thanks for the reply.
Unfortunately that did not do the trick. The column headers are hidden so i do not need to right-align them.
Basically the datagrid has two columns of data. I need the DATA in ONE of the columns to be right aligned.
I tried this:
<Style TargetType="DataGrid">
<Setter Property="CellStyle">
<Setter.Value>
<Style TargetType="DataGridCell">
<Setter Property="HorizontalAlignment" Value="Right"/>
</Style>
</Setter.Value>
</Setter>
</Style>
but that just plain righ-aligns everything in the datagrid (data in column 1 and in column 2). Is it possible to apply this to column 2 only?
Note that i do not have the column definitions in my xaml since the datagrid is populated via a binding.
Thanks
|
|
|
|
|
You can use the AutoGeneratingColumn event to handle this. Source[^].
|
|
|
|
|
I have created a SilverLight application that uses ADO and DomainServices to populate a DataGrid from an SQL 2008 database server. The context looks like this
EcDomainContext context1 = new EcDomainContext();
A few months later, I added a table to the database so in order to use this new table, I had to rebuild as follows:
-deleted all MyDomainServices (.cs) files
-deleted the Mymodel (.edmx) file
-recreate by adding the ADO and Domainservices again
-reconfigure the MyDomainServices.cs as before.
Well, I just added another table and I would like to know if there is an easier way to do this?
Many thanks.
Ps
|
|
|
|
|
hi i have made the stickin which i am moving a small box around it using motion path. but when i change the angle of that stick through slider, the box movement "animation" still remains same the original path which i set the default. is there any way i can change its animation by depending on its angle.
|
|
|
|
|
When working with a XAML file in conjunction with JavaScript and HTML in VisualStudio, whenever I try to set the Loaded attribute in my Grid, my XAML page will fail to load. I get a blank screen and when I right click somewhere in the page, I see a little box saying 'Silverlight'. The JavaScript will also fail to execute.
I get the following message when I try to open the page in Internet Explorer: "Must compile XAML that specifies events".
Surprisingly, the other XAML page (Speeds.xaml) I have does not fail to execute the JS nor the XAML. It runs properly.
Failing XAML file (Accuracy.xaml):
="1.0"="UTF-8"
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="onLoaded">
<Grid.RowDefinitions>
<RowDefinition Height="20*" />
<RowDefinition Height="60*" />
<RowDefinition Height="20*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Grid.Background>
<LinearGradientBrush>
<GradientStop Color="#FF3B596E" />
<GradientStop Color="#FF93C5E8" Offset="1" />
</LinearGradientBrush>
</Grid.Background>
<Canvas Grid.Row="1" Grid.Column="1">
<Canvas.Background>
<LinearGradientBrush>
<GradientStop Color="#FF93C5E8" />
<GradientStop Color="#FF3B596E" Offset="1" />
</LinearGradientBrush>
</Canvas.Background>
<TextBlock Foreground="Ivory" FontSize="16" Canvas.Left="369.68" Canvas.Top="22.29017076">Accuracy</TextBlock>
<Border Width="103.03999999999999" Canvas.Left="103.03999999999999" Canvas.Top="75.76162307999999" BorderThickness="2" BorderBrush="Red" Height="26.73572616">
<TextBlock Text="Sum 1-20" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Border Width="103.03999999999999" Canvas.Left="357.6" Canvas.Top="75.76162307999999" BorderThickness="2" BorderBrush="Red" Height="26.73572616">
<TextBlock Text="Sum 21-40" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Border Width="103.03999999999999" Canvas.Left="612.1600000000001" Canvas.Top="75.76162307999999" BorderThickness="2" BorderBrush="Red" Height="26.73572616">
<TextBlock Text="Sum 41-60" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Line X1="48.480000000000004" Y1="154.9844" X2="758.24" Y2="154.9844" StrokeThickness="2" Stroke="Red" />
<Line X1="48.480000000000004" Y1="154.9844" X2="48.480000000000004" Y2="333.6304" StrokeThickness="2" Stroke="Red" />
<Line X1="48.480000000000004" Y1="200.5612596" X2="758.24" Y2="200.5612596" StrokeThickness="1" Stroke="Red" />
<Line X1="48.480000000000004" Y1="245.1381192" X2="758.24" Y2="245.1381192" StrokeThickness="1" Stroke="Red" />
<Line X1="48.480000000000004" Y1="289.7149788" X2="758.24" Y2="289.7149788" StrokeThickness="1" Stroke="Red" />
<Line X1="48.480000000000004" Y1="334.29183839999996" X2="758.24" Y2="334.29183839999996" StrokeThickness="1" Stroke="Red" />
<Border Canvas.Left="24.240000000000002" Canvas.Top="148.42759999999998" Width="15" HorizontalAlignment="Center">
<TextBlock Text="0" Foreground="Ivory" HorizontalAlignment="Center" />
</Border>
<Border Canvas.Left="24.240000000000002" Canvas.Top="193.0044596" Width="15" HorizontalAlignment="Center">
<TextBlock Text="5" Foreground="Ivory" HorizontalAlignment="Center" />
</Border>
<Border Canvas.Left="24.240000000000002" Canvas.Top="237.5813192" Width="15" HorizontalAlignment="Center">
<TextBlock Text="10" Foreground="Ivory" HorizontalAlignment="Center" />
</Border>
<Border Canvas.Left="24.240000000000002" Canvas.Top="282.1581788" Width="15" HorizontalAlignment="Center">
<TextBlock Text="15" Foreground="Ivory" HorizontalAlignment="Center" />
</Border>
<Border Canvas.Left="24.240000000000002" Canvas.Top="326.73503839999995" Width="15" HorizontalAlignment="Center">
<TextBlock Text="20" Foreground="Ivory" HorizontalAlignment="Center" />
</Border>
<Border Canvas.Left="96.88" Canvas.Top="154.9844" Border.Background="#FF0093DD" Width="30.320000000000004" Height="116.1199" Visibility="Collapsed" x:Name="bar0" MouseLeftButtonUp="test">
<TextBlock Text="13" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="145.35999999999999" Canvas.Top="154.9844" Border.Background="#FF29166F" Width="30.320000000000004" Height="35.7292" Visibility="Collapsed" x:Name="bar1" MouseLeftButtonUp="test">
<TextBlock Text="4" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="193.84" Canvas.Top="154.9844" Border.Background="#FF830F0F" Width="30.320000000000004" Height="26.7969" Visibility="Collapsed" x:Name="bar2" MouseLeftButtonUp="test">
<TextBlock Text="3" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="345.36" Canvas.Top="154.9844" Border.Background="#FF0093DD" Width="30.320000000000004" Height="53.5938" Visibility="Collapsed" x:Name="bar3" MouseLeftButtonUp="test">
<TextBlock Text="6" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="393.84000000000003" Canvas.Top="154.9844" Border.Background="#FF29166F" Width="30.320000000000004" Height="80.3907" Visibility="Collapsed" x:Name="bar4" MouseLeftButtonUp="test">
<TextBlock Text="9" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="442.32" Canvas.Top="154.9844" Border.Background="#FF830F0F" Width="30.320000000000004" Height="44.6615" Visibility="Collapsed" x:Name="bar5" MouseLeftButtonUp="test">
<TextBlock Text="5" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="593.84" Canvas.Top="154.9844" Border.Background="#FF0093DD" Width="30.320000000000004" Height="107.1876" Visibility="Collapsed" x:Name="bar6" MouseLeftButtonUp="test">
<TextBlock Text="12" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="642.32" Canvas.Top="154.9844" Border.Background="#FF29166F" Width="30.320000000000004" Height="26.7969" Visibility="Collapsed" x:Name="bar7" MouseLeftButtonUp="test">
<TextBlock Text="3" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="690.8000000000001" Canvas.Top="154.9844" Border.Background="#FF830F0F" Width="30.320000000000004" Height="44.6615" Visibility="Collapsed" x:Name="bar8" MouseLeftButtonUp="test">
<TextBlock Text="5" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Bottom" />
</Border>
<Border Canvas.Left="96.96000000000001" Canvas.Top="378.87690204" Border.Background="#FF0093DD" Width="200.0" Height="31.19970204">
<TextBlock Text="N° of correct responses" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Border Canvas.Left="296.96000000000004" Canvas.Top="378.87690204" Border.Background="#FF29166F" Width="200.0" Height="31.19970204">
<TextBlock Text="N° of incorrect responses" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
<Border Canvas.Left="496.96000000000004" Canvas.Top="378.87690204" Border.Background="#FF830F0F" Width="200.0" Height="31.19970204">
<TextBlock Text="N° of no responses" Foreground="Ivory" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border>
</Canvas>
</Grid>
Working XAML (Speeds.xaml):
="1.0"="UTF-8"
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Loaded="onLoaded">
</Grid>
Why is this happening and how can I fix this?
modified 16-May-13 5:42am.
|
|
|
|
|
Yes you have the answer, you must compile XAML to BAML in order to use events!
This is what that is done while compiling an app in visual studio. I guess you are trying with an XAML browser project??
|
|
|
|
|
No, I do not have the answer. The problem is not 'Must compile XAML that specifies events'.
The problem is that Visual Studio does not accept XAML files that have Elements whose Background property is set. On my machine it is not compatible with the Background property for some reason. After I set any Background property on my XAML page and I run my project, Visual Studio will show a white page in my Accuracy.html. Everything is white. No content. I am trying to understand why Visual Studio does not accept this Background property.
|
|
|
|
|
Strange?? I do files with a great deal of backgrounds with fancy gradients, images... designed with blend of course??
Well mine is vs2012? yours??
|
|
|
|
|
Hi,
Is this okay to use Frame control in my Main window to load a Xaml page at Runtime?
It also has to support drag/drop feature so that users can drag a control from Toolbox of Main window to the Xaml page in the Frame.
Please suggest/explain.
Thanks.
Be a good professional who shares programming secrets with others.
|
|
|
|
|
You can directly load the view into the user control.
|
|
|
|
|
Whether user control supports drag/drop?
Be a good professional who shares programming secrets with others.
|
|
|
|
|
Hi, I have a treeview where the nodes are generated on runtime.
I want to drag the child node into a canvas a generate an image for each node.
My scenario is i want to allow only certain node to be able to drag and only allow dragging when user want to edit the canvas. How should i achieve that?
Currently I'm using the Silverlight Toolkit TreeViewDragDropTarget.
|
|
|
|
|
I have been working on a project that uses user controls inside other views. What I still can't figure out is how to get a reference to the user control's ViewModel so I can get data off of it or write data to it.
So far, I have been getting a reference to the user control, then getting the VM as the DataContext, then accessing it through that refereence. But this doesn't seem to be right.
In another project I'm using a factory pattern in my AppResources.XAML, such as:
<DataTemplate DataType="{x:Type vm:ClientCenterViewModel}">
<vw:ClientCenterView/>
</DataTemplate>
This does a nice job of pairing the VM to the View, but I can't get a reference to the view's VM to read/write to it.
What's the right way to do this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
You shouldn't need to have access to a child controls VM directly. It's all done via data binding.
<Window>
<Grid>
<MyChildView SomeProp="{Binding SomeProp}" />
</Grid>
</Window>
If you are using DataTemplates to map views <-> VMs, you also don't need access to the VM directly because those views should operate on thier own VMs which would talk to the persistance layer directly.
If you are finding that you need to access a child control/view to do stuff from the code behind, its probably because you didn't expose that functionality with a bindable property. If you don't own the code of the child view, you can expose the functionality you need with a bindable attached behavior.
|
|
|
|
|
Ok, I'm not sure I understand.
In this case I have a Materials view, and on it is a control that lists prices. The prices control is used in more than one view which is why it's a control.
There is a one to many between Materials and Prices, so the prices view needs to know the PK of the Material. In addition, the Material needs to know the count of Prices and other info.
When a material is selected I need to tell the prices view the PK of the selected material so it can load them. When a price is added to the list in the Prices control, the Material view needs to know it.
The Prices control already handles it's own CRUD operations, but I don't understand how it and the Materials view are supposed to intertact. There has to be some way to say "Hey Prices view, give me your data" or, "Hey Prices view, load the prices for this Material".
Using Data Templates to map them seems to make it impossible since the VM for the Materials has no clue that there's a Prices control any where.
If it's not broken, fix it until it is
|
|
|
|
|
Yeah, so its like what I said. Assuming I get what you are talking about . Psuedo-code:
<Window>
<MaterialView />
</Window>
<MaterialView>
<ListView Name="lv" ItemsSource="{Binding ListOfMaterials}" />
<PriceControl Source="{Binding ElementName=lv, Path=SelectedItem.PK}" />
</MaterialView>
Then your PriceControl would auto-magically know when a different material has been selected. But it needs to expose a property that can be data-bound.
EDIT: I just noticed in your response that you wanted to go both ways, so you can do something like:
<MaterialView>
<Label Content="{Binding ElementName=pc, Path=Count" />
</MaterialView>
You just need to expose everything you want to transfer back and forth as a property in the VMs.
The key here is to use the ElementName binding.
|
|
|
|
|
I see. Thanks!
If it's not broken, fix it until it is
|
|
|
|
|
OK, I'd like to ask a follow up question...
Using your code as an example, in the case of the PriceControl, I would have to create a Dependency Property on the control called 'Source', correct?
If so, then that code goes in the control's code behind. How do I 'connect' that Source property to the PricingControl's view model? What I mean is - the view model doesn't know about the Source property, does it?
If it's not broken, fix it until it is
|
|
|
|
|
PriceControl.cs would have something like:
public class PriceControl : Control
{
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register("Source",
typeof(Whatever), typeof(PriceControl), ...);
}
then in your xaml:
<some random tag>
<some other random tag>
<ListView Name="lv" ItemsSource="{Binding Items}" ... />
<PriceControl Name="priceControl" Source={Binding ElementName="lv", Path="SelectedItem"} ... />
</some other random tag>
</some random tag>
Or something of that nature.
You shouldn't really need to refer to Source in the controls VM... you should do it in the XAML... if you use a DataTemplate to define the control's look, you'll be able to refer to the Source property in there.. {Binding Path=Source}...
if you REALLY need to access it in your VM, I think you mentioned SQL calls or something like that, you could define a property in your VM and bind it to Source in the style.
|
|
|
|
|
It's been a month since we last discussed this. I had to put it aside...
So, this morning I create a Sample User Control[^] app to try to do what you suggested here. For the most part I think it's close.
When a Customer is selected, the control should go get the addresses for it. However, the DP's Getter never fires.
This brings me to a question...
Now that I have the DP in the AddressView code behind, when the CustomerId DP is set, how does the VM know about it? What is the connection between the DP in the Code Behind and the VM?
At any rate, I provided a link to the sample. It's pretty small, and I think I coded what you showed me. I would appreciate you taking a quick look to see if you can spot where I'm wrong.
And thanks for all your help so far.
If it's not broken, fix it until it is
|
|
|
|
|
Hello Listeners,
Working on a silverlight application. The data that needs to be returned is very small (1-4 rows)
My domainservice includes following code to populate a datagrid
public IQueryable<products> GetProductsFiltered(int vendorId)
{
return this.ObjectContext.Products.Where(P => P.VendId == vendorId);
}
When the correct value is provided via a “GetProductsFilteredQuery(2)”, the server returns the data and datagird is properly populated.
Now I need to return data based on a column named SiteID so I added another method
public IQueryable<products> GetProductsFilteredSite(int siteId)
{
return this.ObjectContext.Products.Where(P => P.SiteID == siteId);
}
And call it by something like this “GetProductsFilterSiteQuery(5)” . Compiles fine but but error is generated when running the application:
“Local operation failed for query “ GetProductsFilterSite”. The remote server returned an error: NotFound”.
Run the query manually –OK
Fiddler also logs an 504 error “ReadResponse() failed: The server did not return a response for this request.”
But also shows a valid argument passed to GetProductsFilterSiteQuery() method
Any idea is greatly appreciated
|
|
|
|
|
You can try out two things -
1) If you are deploying your service on IIS, you will need to redeploy after adding the new method.
2) You will need to update your service proxy. If you added the website manually, then just right click on the service and refresh.
|
|
|
|
|
Re-publishing the domain services solved my problem.
Many thanks for the help Abhinav
|
|
|
|
|
How to achieve the below layout ? I am new to Silverlight. I need to achieve the same with Paging. Which one is better DataGrid or ListBox ? Can i achieve the same with normal Silverlight but with paging? I dn't want a column header and also my row should have the details filled with Image,Links,Text etc as below...
I want to achieve the same Layout as given in the link http://demos.devexpress.com/AgDataGridDemos/ under the Customization/Row Template tab with Filtering,Sorting and paging functionalities using normal Silverlight Controls. I have to hide the Headers also.
Note: In the example,u can see only Rowtemplate.I wanna acheive exactly same Layout.Go to Link and Click Customization/Row Template tab
|
|
|
|