I found the sample code of "Nick Miller" on the following question:
mvvm how to make a list view auto scroll to a new Item in a list view
This partly answers my question because scrolling works very close, but I need the user can stop automatic scrolling.
To do this I added a checkbox, and in the eveinement puts it true or false the variable listbox.autoscroll, but this has no effect despite the fact that the code will change the property.
I have not changed the Nick Miller code on the LoggingListBox class.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test_Listbox_Autoscroll"
xmlns:tools="clr-namespace:Test_Listbox_Autoscroll"
mc:Ignorable="d"
Title="MainWindow" Width="800"
SizeToContent =" WidthAndHeight">
<Grid>
<StackPanel >
<tools:LoggingListBox x:Name="Listbox1"
Margin=" 10"
Background="Bisque"
Height="180"
ItemsSource="{Binding LST_ListBox1_Collection}"
SelectedItem="{Binding LST_ListBox1_SelectedItem}"/>
<CheckBox x:Name="ChkAutoScroll"
Margin="10"
Content="Auto Scroll"
Click="ChkAutoScroll_Click"/>
</StackPanel>
</Grid>
</Window>
Private Sub ChkAutoScroll_Click(sender As Object, e As RoutedEventArgs)
If (ChkAutoScroll.IsChecked = True) Then
Listbox1.AutoScroll = True
Else
Listbox1.AutoScroll = False
End If
End Sub
There is no error message, but scrolling is still active despite the AutoScroll value change.
Related
As the code showed below I have the main RootViewModel and View where I placed a Content Control, and binded it to ActiveItem. My iusse is that when clicking the button the RedView is not showed, instead is drawed the text StyletTest.RedViewModel.
I need to show the corresponding View in the content control when click a button(here reported only one view and view model to not be too long.) What am I missing?
here the code:
RootView and RootViewModel
<Window x:Class="RootView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:s="https://github.com/canton7/Stylet"
xmlns:local="clr-namespace:StyletTest"
xmlns:syncfusion="http://schemas.syncfusion.com/wpf"
mc:Ignorable="d"
Title="RootView"
Height="300" Width="300" >
<Grid>
<TextBlock>Hello, World</TextBlock>
<Button Command="{s:Action ShowA}" Margin="50,50,50,172" >Click me</Button>
<ContentControl Content="{Binding ActiveItem}" HorizontalAlignment="Left" Height="106" Margin="50,142,0,0" VerticalAlignment="Top" Width="185" />
</Grid>
</Window>
Imports Stylet
Public Class RootViewModel
Inherits Conductor(Of Object)
Private windowManager As IWindowManager
Public Sub New(ByVal windowManager As IWindowManager)
Me.windowManager = windowManager
End Sub
Public Sub ShowA()
Me.ActivateItem(New RedViewModel())
End Sub
End Class
the RedViewModel and RedView:
Imports Stylet
Public Class RedViewModel
Inherits screen
End Class
<UserControl x:Class="RedView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:StyletTest"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid Background="Red">
</Grid>
</UserControl>
The Content property is the wrong one to bind.
I have a ContentDialog, that links it's
<ContentDialog
x:Class="ParadigmaN.Apps.Common.Controls.EditPersonContentDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ParadigmaN.Apps.Common.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Uid="EditorPersonas"
Title=""
PrimaryButtonText="Aceptar"
SecondaryButtonText="Cancelar"
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
SecondaryButtonClick="ContentDialog_SecondaryButtonClick"
PrimaryButtonCommand="{Binding ElementName=CtrPerson,Path=DataContext.GuardarCommand}">
<Grid>
<local:PersonControl x:Name="CtrPerson"/>
</Grid>
</ContentDialog>
But PrimaryButton remains enabled even my CanExecuteCommand returns false.
How Can I control, enabled status of PrimaryButton from a ContentDialog?
There is a property named IsPrimaryButtonEnabled you can use that property to enable or disable PrimaryButton of a ContentDialog.
https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.contentdialog.isprimarybuttonenabled
I am using wix to create a windows installer and I want it to be borderless. Is this possible? If so, how can I create an area on the window where I can drag it from?
Yes.It is possible. Have a look at this.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Height="350" Width="525" WindowStyle="None" ResizeMode="NoResize" >
<Grid >
<Rectangle Fill="Gray" MouseDown="Rectangle_MouseDown" />
<Grid Margin="10" Background="LightGray">
---your window elements go here---
</Grid>
</Grid>
Inside the Rectangle elements mouse down event handler goes your code to drag the window. So if you click on the rectangle i.e the area surrounding your inner Grid, you will be able to drag your window.
private void Rectangle_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
I am trying to upload in a Visual Basic 2010 WPF Mainwindow different Path animation selecting the name of the animation listed in a combobox.
So in a WPF I have my Main window containing a combobox with at this point 2 names in, and I have also Window1 and Window2 each one with a different PathAnimation.
I Do not know how load Animation 1 or Animation 2 in the Main window when the program is running.
I am a little lost
Here is a quick example that I threw together, it is using a ViewBox as a Container. See if this works for you
MainWindow.xmal
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="697" Width="697" xmlns:my="clr-namespace:WpfApplication1">
<Grid>
<Viewbox Name="TrackContainer" VerticalAlignment="Top" HorizontalAlignment="Stretch"></Viewbox>
<Button Content="Button" Height="23" HorizontalAlignment="Center" Margin="360,600,240,0" Name="Button1" VerticalAlignment="Top" Width="75" />
<ComboBox Height="23" Name="ComboBox1" Width="120" SelectionChanged="ComboBox1_SelectionChanged" Margin="41,600,514,35">
<ComboBoxItem Content="Daytona" />
<ComboBoxItem Content="SecondTrack" />
<ComboBoxItem Content="None" />
</ComboBox>
</Grid>
</Window>
MainWindow.xaml.vb
Class MainWindow
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Select Case CType(ComboBox1.SelectedValue, ComboBoxItem).Content.ToString
Case "Daytona"
CType(TrackContainer.Child, UserControl1).runPathAnimation()
Case "SecondTrack"
CType(TrackContainer.Child, UserControl2).runPathAnimation()
End Select
End Sub
Private Sub ComboBox1_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
Dim cmbox As ComboBox = CType(sender, ComboBox)
Select Case CType(cmbox.SelectedValue, ComboBoxItem).Content.ToString
Case "Daytona"
TrackContainer.Child = New UserControl1()
Case "SecondTrack"
TrackContainer.Child = New UserControl2()
Case "None"
TrackContainer.Child = Nothing
End Select
End Sub
End Class
I have tried to set up combo boxes in the gridview but all the combo boxes have the same value in them instead of the value from the database. I am using entity framework and WPF. There is a parent child relationship between two tables but the source for the combo box is a separate table with names and IDs for tags. I have been looking all day. Hopefully this won't be too easy to solve.
The "Tag" Column displays the combo box. The Column "Tag ID" displays the value from the database. When I display the data the TagID Changes in diffrent rows but the Tag column is the same (the first choice) in all the rows. When I change one combo box they all change. I can't see where they are hooked together. Any assistance you can provide would be appreciated. (Buler?)
Here is the XAML
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="372" Width="675" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:TagFinanceWPF">
<Window.Resources>
<CollectionViewSource x:Key="TransactionsViewSource" d:DesignSource="{d:DesignInstance my:Transaction, CreateList=True}" />
<CollectionViewSource x:Key="TransactionsTransactionTagsViewSource" Source="{Binding Path=TransactionTags, Source={StaticResource TransactionsViewSource}}" />
<CollectionViewSource x:Key="TagLookup" />
</Window.Resources>
<Grid DataContext="{StaticResource TransactionsViewSource}">
<ListView ItemsSource="{Binding Source={StaticResource TransactionsTransactionTagsViewSource}}" Margin="12" Name="TransactionTagsListView" SelectionMode="Single">
<ListView.ItemContainerStyle>
<Style>
<Setter Property="Control.HorizontalContentAlignment" Value="Stretch" />
<Setter Property="Control.VerticalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn x:Name="TransactionIDColumn1" Header="Transaction ID" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=TransactionID}" Margin="6,-1,-6,-1" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="TagIDColumn" Header="Tag" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox Margin="-6,-1"
ItemsSource="{Binding Source={StaticResource TagLookup}}"
DisplayMemberPath="TagName"
SelectedValuePath="TagID"
SelectedValue="{Binding TagID}"
IsReadOnly="True">
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn x:Name="TagIDColumn2" Header="Tag ID" Width="80">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding Path=TagID}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
The VB code is:
Class MainWindow
Dim BentleyvideoEntities As TagFinanceWPF.bentleyvideoEntities = New TagFinanceWPF.bentleyvideoEntities()
Private Function GetTransactionsQuery(ByVal BentleyvideoEntities As TagFinanceWPF.bentleyvideoEntities) As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction)
Dim TransactionsQuery As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction) = BentleyvideoEntities.Transactions
'Update the query to include TransactionTags data in Transactions. You can modify this code as needed.
TransactionsQuery = TransactionsQuery.Include("TransactionTags")
'Returns an ObjectQuery.
Return TransactionsQuery
End Function
Private Sub Window_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
'Load data into Transactions. You can modify this code as needed.
Dim TransactionsViewSource As System.Windows.Data.CollectionViewSource = CType(Me.FindResource("TransactionsViewSource"), System.Windows.Data.CollectionViewSource)
Dim TransactionsQuery As System.Data.Objects.ObjectQuery(Of TagFinanceWPF.Transaction) = Me.GetTransactionsQuery(BentleyvideoEntities)
TransactionsViewSource.Source = TransactionsQuery.Execute(System.Data.Objects.MergeOption.AppendOnly)
'Load data into Tags. You can modify this code as needed.
Dim customerList = From c In BentleyvideoEntities.Tags _
Order By c.TagName
Dim custSource = CType(Me.FindResource("TagLookup"), CollectionViewSource)
custSource.Source = customerList.ToList()
End Sub
End Class
I found this while researching your issue and it sounds like the exact same issue you are experiencing.
Snippit from link:
I'm not sure if this will help, but I
was reading in Chris Sells 'Windows
Forms Binding in C#, footnote, page
482', that the data source is bound to
each combobox and is managed by a
common Binding manager which in turn
is part of a Binding Context. The
Binding amager keeps all comboboxes
synchronized to the same row in the
database. However, if each combobox
has a different Binding context, hence
a diferent Binding Manager, then the
combo boxes can show different rows
from the same data source.
Based on this second article (and the suggested solution) you would need to use the row databinding event to set up the combobox's binding so that a new instace of the binding manager is created for each row bind.