|
Hi All,
I want to iterate all the rows of the DataGrid in my SilverLight web application..
Can anyone tell me how to iterate?
I have googled, but no luck....
Thanks,
Sunil G.
|
|
|
|
|
The usual way is not to work against the rows, but rather to work against the underlying data. With Silverlight and WPF it pays to stop thinking in the old ways of doing things, and embrace the rich databinding support along with a pattern such as MVVM.
|
|
|
|
|
I found an exception to that particular rule. There does not seem to be a reasonable way to bind the SelectedItems of the gridview, I'm iterating them in the code behind and stuffing a list<> in the viewmodel.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You could do it by having an
IsSelected property and update that if it's selected.
|
|
|
|
|
Sunil G 3 wrote: I have googled, but no luck....
Thats b/c is is WRONG, as Pete suggested use the underlying data collection
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have several pairs of TextBlock and an Image next to each other. OnMouseLeftButtonDown I want to modify the TextBlock. That is some standard situation, but in this case I don't want to add an EventHandler to each image as there are many of them.
How can I user only one Handler and change the corresponding TextBlock. I've tried to add some DataContext to the image but it did not work out.
Can anyone give me some help?
Thanks!
|
|
|
|
|
You can use the Tag tag to store additional info with your images, for example:
<Image Tag="textbox1" MouseLeftButtonDown="Image_MouseLeftButtonDown" />
<Image Tag="textbox2" MouseLeftButtonDown="Image_MouseLeftButtonDown" /> Now you can access the tag in your event handler, and act based on its value:
private void Image_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) {
var textboxName = ((Image) sender).Tag;
}
|
|
|
|
|
Hi dasblinkenlight,
thank you for your reply. This might be a solution. Would be great to access the textbox directly when an event is fired. Otherwise I need to put all textboxes in an array or not?
I thought of something like this below.
<TextBox x:Name="UserNameTB" />
<TextBox x:Name="AddressTB" />
<Image Source="..." MouseLeftButtonDown="editText_MouseLeftButtonDown" Tag="{UserNameTB}"/>
<Image Source="..." MouseLeftButtonDown="editText_MouseLeftButtonDown" Tag="{AddressTB}"/>
Is it possible to access it like this??
TextBox userNameTB = ((sender as Image).Tag) as TextBox);
Tried some combinations but with no luck.
Greets
Adrian
|
|
|
|
|
Yes, that trick ought to work! I verified that your code works with a slightly modified XAML (I used SilverLight 4):
<Image Source="..." MouseLeftButtonDown="editText_MouseLeftButtonDown" Tag="{Binding ElementName=UserNameTB}"/>
<Image Source="..." MouseLeftButtonDown="editText_MouseLeftButtonDown" Tag="{Binding ElementName=AddressTB}"/>
|
|
|
|
|
If I were doing this, I'd have a collection containing the details of the image, and a text item representing the text you want to display in the TextBlock. Then, I'd bind to this using something like a ListView.
In other words, I'd use MVVM to cope with this. I suggest that you have a look into this, and simplify the problem hugely.
|
|
|
|
|
|
Sounds like a newbie question. But can't help my self for already an hour.
I've Silverlight application with tabs and don't want to put all code in one large file. So I have made single UserControls and now I want to put them into the tab control.
<telerik:RadWindow xmlns:my="clr-namespace:UserEditorApp" x:Class="UserEditorApp.UserDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Height="500" Width="750" Header="User details">
<Grid>
<StackPanel Orientation="Vertical">
<telerik:RadTabControl x:Name="rowDetailsTabControl" ReorderTabRows="False" >
<!-- User Details tab -->
<telerik:RadTabItem x:Name="UserDetailsTab" Header="Benutzer Details">
<StackPanel>
<my:UDW_Details /> <!-- how can I add the control here? -->
</StackPanel>
</telerik:RadTabItem>
</telerik:RadTabControl>
<StackPanel>
</Grid>
</telerik:RadWindow>
I can't see anything in the designer. Can somebody help me out of this?
Thanks!
modified on Thursday, January 20, 2011 8:43 AM
|
|
|
|
|
StackPanels size to the size of the content. In your case, the size is 0x0, so you don't see anything.
You need to have your d namespace defined in the my:UDW_Details XAML and then add:
d:DesignWidth="300" d:DesignHeight="300"
to have a design time width and height.
or you can stub in design time data. Either way works.
|
|
|
|
|
NOW I AM DEVELOPING WPF APPLICATION.THIS APPLICATION I AM USING A ACCORDION CONTROL.IN FIRST TIME I FILL DATA IN IT.AFTER THIS, I WANT FILL NEW DATA TO IT .BUT I CAN"NT FILL TO IT. so please give your subsections
thanks and regards
|
|
|
|
|
1) Dont shout.
2) You can do this. Loop through the items inside an accordion and then remove items from it (or add new items to it).
Sample here[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
I have a treeview with a Template
The treeviewitem has an event handler. I want to access the parent treeviewitem from here. How can I achieve this.
End Goal - User can select a node and delete it.
Template
<br />
<sdk:HierarchicalDataTemplate x:Key="TreeViewMainReadTemplate" ItemsSource="{Binding Children}"><br />
<TextBlock Text="{Binding Text,Mode=TwoWay}" <br />
MouseLeftButtonDown="TreeViewMain_MouseLeftButtonDown"></TextBlock><br />
</sdk:HierarchicalDataTemplate><br />
TreeView
<br />
<sdk:TreeView Name="TreeViewMain" <br />
ItemTemplate="{StaticResource TreeViewMainReadTemplate}" <br />
Width="400" Height="400" ><br />
</sdk:TreeView><br />
Event Handler Where I want to access parent
<br />
private void TreeViewMain_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)<br />
{<br />
}<br />
Binding Data Class
<br />
public class Node<br />
{<br />
private String text;<br />
private ObservableCollection<Node> children;<br />
public ObservableCollection<Node> Children<br />
{<br />
get{ return children;}<br />
set{ children = value;}<br />
}<br />
<br />
public String Text { get { return text; } set { text = value; } }<br />
<br />
public Node(String text)<br />
{<br />
Children = new ObservableCollection<Node>();<br />
Text = text;<br />
}<br />
<br />
public void Add(Node node)<br />
{<br />
children.Add(node); <br />
NotifyPropertyChanged("Children");<br />
}<br />
<br />
public void Delete(Node node)<br />
{<br />
children.Remove(node);<br />
NotifyPropertyChanged("Children");<br />
}<br />
<br />
public event PropertyChangedEventHandler PropertyChanged;<br />
<br />
private void NotifyPropertyChanged(String info)<br />
{<br />
if (PropertyChanged != null)<br />
{<br />
PropertyChanged(this, new PropertyChangedEventArgs(info));<br />
}<br />
}<br />
}<br />
|
|
|
|
|
'sender' should be your Node object. You can then do something like:
Node node = sender as Node;
TreeViewItem tvi = ItemContainerGenerator.ContainerFromItem(node) as TreeViewItem;
You need to be careful here though because the WPF treeview is virtualized, so the TreeViewItem objects come and go as you scroll, collapse, etc. Its possible that ItemContainerGenerator.ContainerFromItem(node) will return null.
|
|
|
|
|
Thanks SledgeHammer01
I was just able to do this using TreeViewExtension part of the silverlight tookit.
TreeViewItem selectedTreeViewItem =
TreeViewExtensions.GetContainerFromItem(TreeViewMain, selectedNode);
if (selectedTreeViewItem != null)
{
TreeViewItem selectedTreeViewItemParent =
TreeViewExtensions.GetParentTreeViewItem(selectedTreeViewItem);
Also thankyou for your suggestions about binding the treeview data. I am doing that, and my life's much easier
|
|
|
|
|
Apologiese.
Wrong post.
modified on Monday, January 17, 2011 9:24 AM
|
|
|
|
|
And what does any of this have to do with Silverlight or WPF?
|
|
|
|
|
Yes you are right.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
My latest tip/trick
|
|
|
|
|
[EDIT]Issue below is solved. Somehow, for some reason, the properties indicating the binding needed to be in uppercase. I was under the impression that oracle was caseINsensative on this point? If anyone can elaborate, please do, because honestly, I don't understand.
[/EDIT]
I have a listview which ItemsSource is set from a dataset. I verified its contents and affter the assigment this property has the correct values.
In my XAML I then defined the GridViewColumns by binding the object-properties to the corresponding column in the grid. A prototype with MS Access worked perfectly. Now we moved to Oracle and changed one column from string to a datetime. To tackle this, I made a valueconverter.
Problem is, for some reason, the grid stays empty. No errors. the Items.Count shows there are items, but they don't show up in the grid. I can also select each row. In addition a breakpoint in the valueconverters classes don't break for some reason.
I'm pretty sure it's or the valueconverter or the XAML that's wrong, but after staring at it for 2 hours and googling I couldn't find my problem.
Does someone recognize this issue (it must be something small and stupid I'm overlooking)? Many thanks !
here's the XAML code:
<ListView Name="lv_logs" ItemsSource="{Binding}" FontSize="12">
<ListView.View>
<GridView>
<GridViewColumn Header="DateTime">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logdts, Converter={StaticResource dts_valueconverter}}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Type">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=logtype, Converter={StaticResource logtype_valueconverter}}" Height="20" Width="20"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logtype}"></TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Actor">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding Path=logactor, Converter={StaticResource logactor_valueconverter}}" Height="20" Width="20"/>
<TextBlock VerticalAlignment="Center" Margin="5,0,0,0" Text="{Binding Path=logactor}"></TextBlock>
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Application" DisplayMemberBinding="{Binding Path=logmodule}"></GridViewColumn>
<GridViewColumn Header="Machine" DisplayMemberBinding="{Binding Path=logmachine}"></GridViewColumn>
<GridViewColumn Header="Message" DisplayMemberBinding="{Binding Path=logmessage}"></GridViewColumn>
</GridView>
</ListView.View>
</ListView>
V.
modified on Monday, January 17, 2011 8:07 AM
|
|
|
|
|
Hi i need some help, my styling is not working a i would like it to.
on the x axis that i try to style i have 4 text´s that says "good", "poor" etc...
The problem is that after i apply the style and change the angel of the text change to about 10 different values 0 and 1
(there are still 4 columnbars displayed)
I want the text good to be at an angle of -64
and adjust the with of the bars to make them smaller
EDIT: The independentvalue bindings displays at the top of the graph, the bottom displays values from 0, 0,1 0,2 0,3 ... 1
can anyone help?
<chartingToolkit:Chart HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="White"
x:Name="Chart"
FlowDirection="LeftToRight"
Margin="6,1,1,1"
Grid.Column="0"
Grid.Row="0"
Title="Score"
FontFamily="Arial"
FontSize="10.667"
BorderThickness="0,1,1,1">
<chartingToolkit:Chart.LegendStyle>
<Style TargetType="Control">
<Setter Property="Width"
Value="0" />
<Setter Property="Height"
Value="0" />
</Style>
</chartingToolkit:Chart.LegendStyle>
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="X">
<chartingToolkit:LinearAxis.AxisLabelStyle>
<Style TargetType="chartingToolkit:AxisLabel">
<Setter Property="RenderTransformOrigin"
Value="0.8,0.8" />
<Setter Property="RenderTransform">
<Setter.Value>
<RotateTransform Angle="-65" />
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:LinearAxis.AxisLabelStyle>
</chartingToolkit:LinearAxis>
</chartingToolkit:Chart.Axes>
<chartingToolkit:ColumnSeries x:Name="ScoringColumn"
IndependentValueBinding="{Binding Scoring}"
DependentValueBinding="{Binding Number}"
Title="Series 1" />
</chartingToolkit:Chart>
modified on Monday, January 17, 2011 6:07 AM
|
|
|
|
|
I got it working, i replaced LinearAxis with CategoryAxis.
|
|
|
|
|
Hello,
When i wrote a "Source" property as full path "C:\aaa\aaa\aaa\aa\fileName" i do hear the sound, but when i'm trying to set the path using the resources, it doesn't work (no sound), i've marked build actions of the media file as "resources". and in source i wrote /namespace;component/Resources/filename
What i'm doing wrong here ?
thanks
|
|
|
|