|
hello
I added a scrollbar, but it does not work
help me please
<ListView ItemsSource="{Binding GameCollection}" ScrollViewer.VerticalScrollBarVisibility="Visible">
here is the immgine of my problem
linkToSnap
|
|
|
|
|
Hello, I have a DataGrid that I am using where the user clicks a button to add information to the DataGrid. I would like to set focus to the first cell when the user clicks the button. My previous code worked great in a plain ol' DataGridTextColumn, but no longer works.
Here is my XAML:
<DataGrid.Columns>
<DataGridTemplateColumn x:Name="partName"
Header="Part Name"
CanUserResize="True"
Width="225"
MinWidth="225">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock VerticalAlignment="Center" Focusable="True" FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}">
<Hyperlink NavigateUri="http://www.bing.com"
RequestNavigate="Hyperlink_RequestNavigate"
TextDecorations="None">
<TextBlock Text="{Binding Path=description}" x:Name="hyperLinkTextBlock"
FontSize="20"
FontWeight="Black"
TextWrapping="WrapWithOverflow"
TextDecorations="Underline"
Focusable="True"
FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"/>
</Hyperlink>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox FontSize="20"
FontWeight="Black"
HorizontalAlignment="Stretch"
VerticalContentAlignment="Center"/>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
And here is my C# code:
partsDataGrid.Focus();
partsDataGrid.UpdateLayout();
DataGridCellInfo cellInfo = new DataGridCellInfo (partsDataGrid.Items[0], partsDataGrid.Columns[0]);
partsDataGrid.CurrentCell = cellInfo;
partsDataGrid.BeginEdit();
What am I doing wrong? Thanks in advance!
|
|
|
|
|
Just for anyone else, I discovered my problem. Even though I had set everything inside my DataGridTemplateColumn to focusable, I hadn't set focusable to true inside my CellStyle.
|
|
|
|
|
I have a custom user control that inherits FrameWorkElement and draws some custom shapes on a canvas. I added this code to get the context menus for the item:
Sub New()
......
Dim contextmenu As New ContextMenu()
Dim mi As New MenuItem()
Dim mia As New MenuItem()
mi.Header = ("Item 1")
contextmenu.Items.Add(mi)
mia.Header = ("Item 2")
contextmenu.Items.Add(mia)
AddHandler contextmenu.MouseLeave, AddressOf CloseContextmenu
Me.ContextMenu = (contextmenu)
End Sub
Private Sub CloseContextmenu(ByVal sender As Object, ByVal e As Input.MouseEventArgs)
Me.ContextMenu.IsOpen = False
End Sub
Which does close the contextmenu, but not when you leave the menu, only when you click outside the contextmenu. My question is has anybody managed to close the contextmenu on mouse leave?
|
|
|
|
|
Ok, I nearly sovled this myself, though its not the ideal solution:
If Mouse.RightButton = MouseButtonState.Pressed Then
If TypeOf (selectedElement) Is CustomElement Then
Dim ga As CustomLine = DirectCast(selectedElement, CustomElement)
Dim contextmenu As New ContextMenu()
Dim bord As New StackPanel
Dim mi As New MenuItem()
Dim mia As New MenuItem()
mi.Header = ("Item 1")
mia.Header = ("Item 2")
bord.Children.Add(mi)
bord.Children.Add(mia)
AddHandler bord.MouseLeave, AddressOf menuitem1_leave
contextmenu.Items.Add(bord)
contextmenu.IsOpen = True
ga.ContextMenu = (contextmenu)
End If
End If
with the mouse leave sub:
Private Sub menuitem1_leave(ByVal sender As Object, ByVal e As Input.MouseEventArgs)
Dim dep As DependencyObject = DirectCast(e.OriginalSource, DependencyObject)
While (dep IsNot Nothing) AndAlso Not (TypeOf dep Is ContextMenu)
dep = VisualTreeHelper.GetParent(dep)
End While
If dep Is Nothing Then
Exit Sub
End If
DirectCast(dep, ContextMenu).IsOpen = False
End Sub
Problem is that the items are messed up inside the ContextMenu, so it looks wierd. So the next question is does anybod have any ideas on how to do this properly?
|
|
|
|
|
When I set AutoGenerateColumns = false, then I see no data. I see the data when AutoGenerateColumns = True. Here's my grid:
<DataGrid Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
Margin="5"
ItemsSource="{Binding AccountItems}"
SelectedItem="{Binding SelectedAccountItem}"
AutoGenerateColumns="True">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Date"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding DisplayDate}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Memo 1"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Memo1}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Memo 2"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Memo2}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Debit"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Debit}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Credit"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Credit}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Balance"
Width="SizeToCells"
IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Balance}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
What am I doing wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Not exactly sure but the http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.autogeneratecolumns.aspx[^] seems to give an answer:
<DataGrid Name="DG1" ItemsSource="{Binding}" AutoGenerateColumns="True" AutoGeneratingColumn="DG1_AutoGeneratingColumn" />
and in the code behind:
private void DG1_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
string headername = e.Column.Header.ToString();
if (headername == "MiddleName")
{
e.Cancel = true;
}
if (headername == "FirstName")
{
e.Column.Header = "First Name";
}
else if (headername == "LastName")
{
e.Column.Header = "Last Name";
}
else if (headername == "EmailAddress")
{
e.Column.Header = "Email";
}
}
You could use the code and step through the code with the debugger, at least then you could see whats going on.
modified 20-Sep-12 18:10pm.
|
|
|
|
|
Kenneth Haugland wrote: Windows Forms Designer
He's talking about WPF, not Windows Forms, and he's put what looks like well formed templates in there.
|
|
|
|
|
Dang it...
|
|
|
|
|
Hard to say from that - we only have half the picture here. Tell you what, what do you see if you change the DataGridTemplateColumns into DataGridTextColumns? What appears in the text? Is the source correct then?
|
|
|
|
|
That did it. Thanks Pete
If it's not broken, fix it until it is
|
|
|
|
|
|
made stackedbarseries in silverlight to show "projects gantt chart"
now I wanna change the numbers shown in the Axes-X for example we have Worker John:
pr1: 201105 - 201115
pr2: 201120 - 201144
pr3: 201142 - 201207
etc...
so I made 2 series that the first seria is with tranceparent color then I make function that change the WW to range from 201101 (dont need before..) so the chart looks like:
pr1: 5-15
pr2: 20-44
pr3: 42-60 (53+7 or 52+7 depends on year)
now how can I change the Axes display to the original?
the code in xaml is:
<toolkit:Chart Name="ProjectChart" Title="Projects" Visibility="Visible" >
<toolkit:Chart.Series>
<toolkit:StackedBarSeries FontWeight="Bold" MouseLeftButtonUp="StackedBarSeries_MouseLeftButtonUp" MouseEnter="StackedBarSeries_MouseEnter">
<toolkit:SeriesDefinition ItemsSource="{Binding}" Visibility="Collapsed" Title="" Name="serEmpty"
DependentValueBinding="{Binding tranceparent_ser}"
IndependentValueBinding="{Binding projectName}"
>
<toolkit:SeriesDefinition.DataPointStyle>
<Style TargetType="toolkit:BarDataPoint">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
</Style>
</toolkit:SeriesDefinition.DataPointStyle>
</toolkit:SeriesDefinition>
<toolkit:SeriesDefinition ItemsSource="{Binding}" Title="Project" Name="serProjects"
DependentValueBinding="{Binding project_ser}"
IndependentValueBinding="{Binding projectName}">
<toolkit:SeriesDefinition.DataPointStyle>
<Style TargetType="toolkit:BarDataPoint">
<Setter Property="Background" Value="Blue"/>
<Setter Property="BorderBrush" Value="Blue"/>
<Setter Property="BorderThickness" Value="1"/>
</Style>
</toolkit:SeriesDefinition.DataPointStyle>
</toolkit:SeriesDefinition>
</toolkit:StackedBarSeries>
</toolkit:Chart.Series>
</toolkit:Chart>
thanks
|
|
|
|
|
I have an XML file structured this way:
<Emulators>
<Settings>
<vol name="10"/>
<Volume>10</Volume>
<Keys name="key1" value="1" />
<Keys name="key2" value="2" />
<Keys name="key3" value="3" />
<Keys name="key4" value="4" />
</Settings>
<System>
<Name>name1</Name>
<Icon>name1.png</Icon>
<topplayed>
<Top>top1</Top>
<Top>top2</Top>
<Top>top3</Top>
</topplayed>
</System>
<System>
<Name>name2</Name>
<Icon>name2.png</Icon>
<topplayed>
<Top>top4</Top>
<Top>top5</Top>
<Top>top6</Top>
</topplayed>
</System>
</Emulators>
I get no difficulties binding to <settings> tag, as well as tags contained into it.
I get no difficulties to bind the <system> tag into a list box.....but I don't know how to bind to tags into <topplayed>.
How to populate a listbox with all <topplayed> elements of the currently selected <system>?
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="721" Width="525" Background="#FF4E4E64">
<Grid Name="Grid1">
<Grid.DataContext>
<XmlDataProvider x:Name="SystemData" Source="C:\Users\Portable\Desktop\taper\WpfApplication1\Resources\Systems2.xml" XPath="Emulators" />
</Grid.DataContext>
<Grid.Resources>
<DataTemplate x:Key="Resource1">
<Label Content="{Binding XPath=@name}"/>
</DataTemplate>
<DataTemplate x:Key="Resource2">
<Label Content="{Binding XPath=@value}"/>
</DataTemplate>
<DataTemplate x:Key="Resource3">
<Label Content="{Binding XPath=Name}"/>
</DataTemplate>
<DataTemplate x:Key="Resource4">
<Label Content="{Binding XPath=Top}"/>
</DataTemplate>
</Grid.Resources>
<TextBox Text="{Binding XPath=Settings/Volume}" Height="30" HorizontalAlignment="Left" Margin="12,12,0,0" Name="TextBox5" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource1}" IsSynchronizedWithCurrentItem="True" Height="92" HorizontalAlignment="Left" Margin="12,48,0,0" Name="ListBox1" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=Settings/Keys}" ItemTemplate="{StaticResource Resource2}" Height="92" HorizontalAlignment="Left" IsSynchronizedWithCurrentItem="True" Margin="214,48,0,0" Name="ListBox2" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=System}" ItemTemplate="{StaticResource Resource3}" IsSynchronizedWithCurrentItem="True" Height="104" HorizontalAlignment="Left" Margin="12,185,0,0" Name="ListBox3" VerticalAlignment="Top" Width="196" />
<ListBox ItemsSource="{Binding XPath=System/topplayed}" ItemTemplate="{StaticResource Resource4}" Height="74" HorizontalAlignment="Left" Margin="12,295,0,0" Name="ListBox4" VerticalAlignment="Top" Width="196" />
</Grid>
</Window>
Thank you very much!!
|
|
|
|
|
Hi All,
I need to play streaming videos like Live TV News and live Cricket etc. in my WPF Application.
I used Media Element But it did not worked out. If anyone has done that in any way please help me out.
|
|
|
|
|
Take a look at the sticky at the top on how to ask a question, yours was not a good example and will not get the answer you want. Try reading some of the articles, work through the samples[^] there are plenty out there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
So I have this XAML code:
<Window.Resources>
<local:MainViewModel x:Key="ViewModel" />
</Window.Resources>
And this is the XAML for the actual control:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Width="897" >
<RadioButton GroupName="Intersections"
Content="{Binding Text}"
IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
In the code behind I have this public class:
Public Class MainViewModel
Sub New()
Intersections.Add(New Insertion() With {.Text = "Item 1"})
Intersections.Add(New Insertion() With {.Text = "Item 2", .IsChecked = True})
Intersections.Add(New Insertion() With {.Text = "Item 3"})
Intersections.Add(New Insertion() With {.Text = "Item 4"})
End Sub
Private _Intersections As New ObjectModel.ObservableCollection(Of Insertion)
Public Property Intersections() As ObjectModel.ObservableCollection(Of Insertion)
Get
Return _Intersections
End Get
Set(ByVal value As ObjectModel.ObservableCollection(Of Insertion))
_Intersections = value
End Set
End Property
Public Class Insertion
Private _Text As String
Public Property Text() As String
Get
Return _Text
End Get
Set(ByVal value As String)
_Text = value
End Set
End Property
Private _IsChecked As Boolean
Public Property IsChecked() As Boolean
Get
Return _IsChecked
End Get
Set(ByVal value As Boolean)
_IsChecked = value
End Set
End Property
End Class
End Class
The problem Im haveing is to get the RadioButtons to be shown Horizantaly, and I cant figure out how to do that. I have tried to set IsItemsHost="True" but Its giving me the error "A panel with IsItemsHost="true" is not nested in an ItemsControl. Panel must be nested in ItemsControl to get and show items." . Either I heave tried to do this in all the wrong places or Im missing some key information here.
To be clear the code works, but its giving me a stack of the RadioButtons, but I want the side by side like a WrapPanel.
The example is taken from here here[^], and I converted it to VB from C#.
modified 17-Sep-12 13:49pm.
|
|
|
|
|
Use ItemsPanelTemplate and put the radio buttons horizontally inside a stack panel.
E.g.
<ItemsControl.ItemTemplate>
<ItemsPanelTemplate>
<StackPanel Orientation='Horizontal' "/>
</ItemsPanelTemplate>
|
|
|
|
|
I tried this:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal">
<RadioButton GroupName="Intersections"
Content="{Binding Text}"
IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</StackPanel>
</ItemsPanelTemplate>
</ItemsControl>
</StackPanel>
But this time it wont build properly with ItemsPanelTemplate, I have seen this on the webbefore also, but couldnt get it to work, Can you?
|
|
|
|
|
I think (though Im not sure), one needs to put the <itempresenter> tag somewhere.
|
|
|
|
|
ITs working now, but its a strange code, and its well over a page long, so I dont think I'll be pasting it here, unless you are really interested
|
|
|
|
|
Ok Found the answer here[^] . The code that works looked like this:
<StackPanel Orientation="Horizontal" Width="897" Margin="5" DataContext="{StaticResource ViewModel}">
<ItemsControl Width="897" ItemsSource="{Binding Intersections}">
<ItemsControl.Template>
<ControlTemplate>
<WrapPanel Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
FlowDirection="LeftToRight" IsItemsHost="true">
</WrapPanel>
</ControlTemplate>
</ItemsControl.Template>
<ItemsControl.ItemTemplate>
<DataTemplate>
<WrapPanel Width="120">
<RadioButton GroupName="Intersections" Content="{Binding Text}" IsChecked="{Binding IsChecked, Mode=TwoWay}" Width="150"/>
</WrapPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
|
|
|
|
|
I have this combobox:
<ComboBox x:Name="cboServerList"
Grid.Row="0"
Grid.Column="1"
Margin="5"
Height="23"
IsEditable="True"
ItemsSource="{Binding Servers}"
SelectedItem="{Binding SelectedServer}"
TextSearch.TextPath="ServerName"
Text="{Binding ServerName}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding ServerName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Since it's editable, as soon as I start typing the SelectedServer property's setter fires. How can I set it up so that it doesn't fire until the user presses Enter or tabs out?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Set the UpdateSourceTrigger of the binding to LostFocus. That won't handle the enter key though. Which is probably ok since the enter key has a different meaning. Dunno why you'd want to do this though. Sounds like an issue with your VM setter being too expensive??
|
|
|
|
|
Thanks for the tip
SledgeHammer01 wrote: Dunno why you'd want to do this though. Sounds like an issue with your VM
setter being too expensive??
Why would you want the property's get to fire on each keystroke?
If it's not broken, fix it until it is
|
|
|
|