|
You're attempting to bind to a property that doesn't exist. Your Tag property is actually a property of the CheckBox which is, itself, bound to a different property on your ViewModel. So, you need to set your Trigger to use the underlying property. In other words, replace Binding="{Binding Tag}" with Binding="{Binding FunctionCode}" . If you'd checked your Output window when debugging your application, you'd probably have seen a binding error telling you that this was missing.
This space for rent
|
|
|
|
|
Hi Pete,
Thanks for your response!!
Actually , both ways xaml is not throwing error and neither working. As per your suggestion i have changed trigger i.e.
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding FunctionCode}" Value="CMDSDMODIFYFEATURES">
<Setter TargetName="TheBorder" Property="Background" Value="Blue" />
</DataTrigger>
</DataTemplate.Triggers>
Even after this change background color is not getting changed for checkbox holding tag value "CMDSDMODIFYFEATURES". Am i setting up a setter in correct way?
Regards
|
|
|
|
|
Someone please help me out achieving this ...
Regards
Saurabh
|
|
|
|
|
Hello Everyone,
I found the answer myself, here is how to achieve this :
<DataTemplate.Triggers>
<Trigger SourceName="radioButZone" Property="Tag" Value="CMDDSDMODIFYFEATURES">
<Setter Property="BorderBrush" Value="Orange" TargetName="TheBorder"/>
</Trigger>
</DataTemplate.Triggers>
Thanks everyone for your support
|
|
|
|
|
Hai
I want to create a simple WPF datagrid using vb.net. I added datagrid1 and added 2 columns from designer and binded it from xaml.
XAML
<DataGridTextColumn Binding="{Binding Path=LastName}" ClipboardContentBinding="{x:Null}" CanUserReorder="False" CanUserResize="False" Width="200" Header="LastName" HeaderStringFormat="LastName"/>
Second column
<DataGridTextColumn Binding="{Binding Path=FirstName}" ClipboardContentBinding="{x:Null}" Header="FirstName" HeaderStringFormat="FirstName" CanUserSort="False" CanUserReorder="False" CanUserResize="False" FontSize="16" Width="100">
I use this code
<pre lang="VB.NET">
Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim _customers = New List(Of Customer)
DataGrid1.ItemsSource = _customers
End Sub
Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
&#39;Here I want to add an empty row
End Sub
Public Class Customer
Private _firstName As String
Private _lastName As String
Public Property FirstName() As String
Get
Return _firstName
End Get
Set(ByVal value As String)
_firstName = value
End Set
End Property
Public Property LastName() As String
Get
Return _lastName
End Get
Set(ByVal value As String)
_lastName = value
End Set
End Property
End Class</pre>
My problem is an empty row is automatically added below, I want only to add row in button click event
Please tell me how to do this, or is there any method without using data source
Thanks
|
|
|
|
|
Try setting the
.CanUserAddRows property to false on the DataGrid.
|
|
|
|
|
Thanks for reply it is working
Also please tell me how to add a new row in button click
|
|
|
|
|
No it is a serious question - scenario...
WCF with a single data access class,
A data service class for each table/view in the database. This maps a datatable to the model
A model class for each table/view in the database to be passed in a List<> to the client - implements OnPropertyChanged
WPF client that uses the WCF and retrieves List<> of the models. The client is set to reuse the WCF objects (Models)
This means I do not have to remap the WCF models to client models, however chasing down a potential memory leak I find I have multiple copies of the models in memory. I have 1 particular view with 35 master lists (servicing comboboxes) and another 7 lists used for multi selects over 2 Tabs. Fricking nightmare! This view can take between 2 and 12 seconds to load and I'm attempting to find out why.
So the question should I be passing POCO objects from the WCF and converting them to local models with the OPC implementation?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Why pass a POCO when only a scalar might be needed?
|
|
|
|
|
I pass all manner of objects, including scalar values. The point is that when I pass a list it is a List<> of a class with the OnPropertyChanged events included rather than a List<> of POCO objects. Is this likely to cause memory leaks?
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The OnPropertyChanged handler is null until a presenter subscribes to it. Can't think of any other references that might cause a problem.
|
|
|
|
|
Tracked the problem down to the binding the selected object to the form, just too many comboboxes, the object has over 50 fields and binds to 30 comboboxes on the one view.
I gave them a couple of options, split the view or change to popups instead of combo boxes. The decided to live with the issue - bloody users.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I used to "virtualize" these clumsy scenarios (combo boxes) into windows with data base smart grids.
|
|
|
|
|
How did you pop the windows, button or mouse over?
This is another option I am considering as there is a lot of looking but not a great deal of modification after the object is created.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'd pop the window on demand (e.g. F4 or a right-mouse click while a data-entry field has focus) or on trying to exit the field after typing an invalid entry. The intent was to minimize key strokes and mouse moves and maintain flow.
modified 27-Nov-15 20:37pm.
|
|
|
|
|
<ListView x:Name="lvBookings" VirtualizingStackPanel.IsVirtualizing="True" MinHeight="300" MinWidth="850" ItemsSource="{Binding ListViewItemsCollections}" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn Header="Venue" Width="100" DisplayMemberBinding="{Binding Venue}"/>
<GridViewColumn Header="Date" Width="100" DisplayMemberBinding="{Binding Date}"/>
<GridViewColumn Header="Status" Width="100" DisplayMemberBinding="{Binding Status}"/>
<GridViewColumn Header="Duration" Width="100" DisplayMemberBinding="{Binding Duration}"/>
<GridViewColumn Header="TimeIn" Width="100" DisplayMemberBinding="{Binding TimeIn}"/>
<GridViewColumn Header="TimeOut" Width="100" DisplayMemberBinding="{Binding TimeOut}"/>
<GridViewColumn Header="Progress" Width="100">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ProgressBar Name="pbDuration" Value="{Binding ProgressValue}" Minimum="0" Maximum="{Binding MaxValue}" Width="100"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
modified 22-Nov-15 7:40am.
|
|
|
|
|
It would depend, I believe, on how you want to use it. If you are trying to set its visible property, for example, you might try the "Path=" or the ElementName= syntax. I am pretty new to WPF but accessing child controls of the element tree ought to be the same as when you need to bind to another element.
I hope this helps. As I said, I am sort of a beginner.
Joey
Joseph M. Morgan
|
|
|
|
|
So I'm learning about Routed Events. I just found this[^] excellent blog post.
I understand what it does, but why not just do this:
public delegate void ButtonWasClickedEventHandler();
public event ButtonWasClickedEventHandler ButtonWasClicked;
private void raiseButtonWasClicked()
{
if (ButtonWasClicked != null)
{
ButtonWasClicked();
}
}
and then in the parent control:
<local:ChildControl Margin="61,87,108,95"
ButtonWasClicked="ChildControl_ButtonWasClicked"/>
and
private void ChildControl_ButtonWasClicked()
{
}
Basically, I don't see the point of the routed event. A Standard event works fine.
If it's not broken, fix it until it is
|
|
|
|
|
|
Hi,
I want to change silverlight 4 datepicker format as 'dd/MM/yyyy' in one page only. I tried below code
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern = "dd/MM/yyyy";
But It changes format in whole silverlight application. I want datepicker change format in one silverlight page only.
Please give me solution.
Thanks.
Regards,
Suchita Gorivale
|
|
|
|
|
You need to include Stringformat in the binding xaml.
{Binding YourDateField, StringFormat='dd/MM/yyyy'}
Take a read of this article[^]
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want my button to be enable only when one item in listbox is checked else disable the button. how to achieve this? Any help please
<ListBox Name="listBoxDraftVersions" Height="200" Width="250" Margin="3" ItemsSource="{Binding DraftList}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border x:Name="TheBorder" BorderBrush="Gray" BorderThickness="1" Padding="4" CornerRadius="4" Margin="2">
<CheckBox Name="radioButZone" Content="{Binding DraftName}" IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}"></CheckBox>
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="AliceBlue" Offset="0.15" />
<GradientStop Color="White" Offset="0.85" />
<GradientStop Color="Lavender" Offset="1" />
</LinearGradientBrush>
</Border.Background>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Content="Load" IsDefault="True" x:Name="btnLoad" Style="{StaticResource MetroButton}" Click="btnLoad_Click" />
i tried
IsEnabled="{Binding ElementName=listBoxDraftVersions, Path=IsSelected}" not working
|
|
|
|
|
Add a DataTrigger to your Button; e.g.
<Button Content="Load"
IsDefault="True"
x:Name="btnLoad"
Click="btnLoad_Click">
<Button.Style>
<Style TargetType="Button">
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=listBoxDraftVersions, Path=SelectedItems.Count}"
Value="0">
<Setter Property="IsEnabled"
Value="False" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
|
|
|
|
|
Hi Gerry,
Thanks for your quick reply , same thing is happening if i use
IsEnabled="{Binding ElementName=listBoxDraftVersions, Path=SelectedItems.Count}" on button.
But i want button to be enabled when only 1 checkboox is checked else it should be diabled if >1 and <1
Thanks and Regards
|
|
|
|
|
"IsEnabled" is a bool; simply trying to bind it to SelectedItems.Count (an int) is not going work.
You might be able to use a "converter" in there ...
(Or just change the trigger to "enable" the button if the "count" is 1; using a default of "not enabled").
|
|
|
|