|
|
Hi,
I have defined a combobox inside a DataTemplate.
I would like to access the selected item through the SelectedItemChanged event.
Problem: the comboBox seems to be not accessible from code behind.
Could someone tell me how to proceed?
RV
xaml:
<groupbox grid.row="1" grid.column="0" background="Transparent" margin="2,0,5,0">
<groupbox.header>
On going actions list view
<dockpanel grid.row="1" background="Transparent">
<datagrid name="dataGridActionsToPerform" autogeneratecolumns="False"
="" background="Transparent" borderbrush="Transparent">
<datagrid.resources>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
<Border Name="Border"
BorderThickness="0,0,0,1"
BorderBrush="Gainsboro"
CornerRadius="4,4,0,0"
Margin="2,0">
<TextBlock x:Name="ContentHeader"
Text="{TemplateBinding Content}"
Padding="5,5,5,0"
Width="{TemplateBinding Width}"
TextAlignment="Center">
</textblock>
</border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="True">
<Setter TargetName="Border"
Property="Background" Value="LightGray">
</setter>
</trigger>
</controltemplate.Triggers>
</controltemplate>
</setter.Value>
</setter>
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Foreground" Value="Black" />
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontSize" Value="12" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border x:Name="Border" SnapsToDevicePixels="true">
<GridViewRowPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
<Border.Style>
<Style TargetType="Border">
<Style.Triggers>
<DataTrigger Binding="{Binding ColorProperty}" Value="Black">
<Setter Property="Background" Value="Blue"/>
</datatrigger>
<DataTrigger Binding="{Binding ColorProperty}" Value="Red">
<Setter Property="Background" Value="Red"/>
</datatrigger>
</style.Triggers>
<datagrid.columns>
<datagridtextcolumn header="Actions"
="" width="220" binding="{Binding ActionName}">
<datagridtemplatecolumn header="Control"
="" width="50">
<datagridtemplatecolumn.celltemplate>
<datatemplate>
<combobox name="ControlActionComboBox"
="" itemssource="{Binding CollectionOfPictures, Mode=TwoWay}" selectionchanged="controlAction_SelectionChanged" selecteditem="{Binding SelectedItem, Mode=TwoWay}">
<combobox.itemcontainerstyle>
<Setter Property="Padding" Value="5"/>
<Setter Property="BorderBrush" Value="LightGray"/>
<Setter Property="BorderThickness" Value="1"/>
<combobox.itemtemplate>
<datatemplate>
<dockpanel>
RV
|
|
|
|
|
Your question is incongruent.
The simplest explanation is that the "code behind" you are "probably" looking for is wired to the following event handler:
SelectionChanged="controlAction_SelectionChanged"
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Thank you Gerry for your reply,
Actually I had in mind to do a treatment, depending on the selected item. For that purpose, it is essential to determine which item was selected from controlActionComboBox.
But in the code behind I cannot address this comboBox through its name. That's the issue.
And I cannot figure out how to do what I have in mind.
Best regards,
RV
|
|
|
|
|
You can't wire up to an item in your DataTemplate directly. That's not the way that DataTemplates work. You'll need to do something like this[^] and then add the event handlers.
This space for rent
|
|
|
|
|
Thank you Pete for your reply,
I've finally got the solution to this issue through:
string text = (((sender as ComboBox).SelectedItem) as ActionPicture).ImageName
Where ActionPicture is the picture enclosed in the selected. And ImageName is the name of that picture.
Best regards,
Rv
|
|
|
|
|
Hi I need to refactor this code..thanks in advance for any help!!
public MyListViewModel GetData(List<UpdatingViewModel> updatingList, MyListViewModel myList)
{
foreach(UpdatingViewModel x in updatingList)
{
x.Gain = myList.UpdatingView[0].Gain;
x.Amount = myList.UpdatingView[0].Amount;
x.Minimum = myList.UpdatingView[0].Minimum;
x.Charge = myList.UpdatingView[0].Charge;
x.abc = myList.UpdatingView[0].abc;
}
}
|
|
|
|
|
Start by renaming the method. A method that updates something should not be called Get... !
Fix the compilation error. The method is declared as returning a MyListViewModel , but it doesn't return anything.
Then provide a proper description of what you're trying to do, what you've tried, and where you're stuck.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
How do you know when you've succeeded?
Is it: abc; Abc; ABC?
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
add new tools to my tool box as *.dll file.
|
|
|
|
|
Simplest way?
Open the Design view on any form.
Open the Toolbox pane.
Close branches so you get "clear space".
Use Windows explorer to browse to the DLL or EXE file containing your controls.
Drag the Assembly file to the ToolBox and drop it there.
You can also create a new Tab first, and drop them on that if you want it a bit tidier.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Now, I am building an application like Russian dictionary. How to program the Russian pronunciation in C #, which library to use? Does the Speech or Speech.lib libraries contain "text to speech" functions for Russian as well as for English? Please Help me solve text russian to speech in C # using library or not?
modified 20-Dec-17 7:32am.
|
|
|
|
|
According to this[^], yes it does. BTW, remove your email address from your signature - that's a sure fire way to get spammed.
This space for rent
|
|
|
|
|
Thank you so much. Can you show me how to use the SDK? Currently I'm using C # 2012 but have not installed the SDK in C #? Please show me how to use it.
|
|
|
|
|
Google not working at your end?
|
|
|
|
|
Hi everybody,
I'm currently developing an application in which I have to drag a video from in a media element into another container (let's say a kind of library). The video must keep playing in the media element and only a copy is "stored" in that library.
All the videos present in the library must be visible in order to eventually be reloaded (through drag and drop) into the media player for vizualization.
Have someone an idea on how this could be achieved?
Best regards,
RV
|
|
|
|
|
|
Thank you Richard for your reply,
I'm gonna read this article and find out how it can be helpful for my project.
RV
|
|
|
|
|
Hello
I should save appointments on the shared exchange calendar,
how can I do
|
|
|
|
|
CTRL+S?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Hi guys,
Probably a simple task but i'm struggling with it.
I have a list of objects, lets call this a list of Object1. Each Object1 contains a list of another object lets say Object2.
Object2 has 2 properties. 'Name' and 'Value'.
I want to be able to select Object1 where Object2.Name equals a specified value using lambda.
eg
class Object2
{
public string Name {get; set;}
public string Value {get; set;}
}
class Object1
{
public List<Object2> theList = new List<Object2>(){ new Object2(){Name = "Blah", Value = "Blah"}};
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
var myList = Object1.Where(m => m.theList.Name == "Blah")
}
}
I hope I explained myself clearly.
Many thanks for your help
Br
Nigel
|
|
|
|
|
There are a lot of things wrong with that!
Object1 is a class, not a collection, so you can;t use Where on it.
Name is not a property of the list, it;'s a property of teh objects teh list contains.
Try this:
List<Object1> myList = new List<Object1>();
myList.Add(new Object1());
myList.Add(new Object1());
myList.Add(new Object1());
IEnumerable<Object1> myResults = myList.Where(m => m.theList.FirstOrDefault(o => o.Name == "Blah") != null);
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Thanks Member 12616185,
Yes, Object1 was meant to be a collection of Object1's. My bad for not proof reading. Thanks for spotting and correcting.
Your reply worked a treat. Here's the implementation I used which served my purpose.
var myResults = Object1.Where(m => m.Object2.Select(o => o.Value == "802.11g") != null);
Many thanks again for the help
Br
Nigel
|
|
|
|
|
Member 12616185 wrote:
var myResults = Object1.Where(m => m.Object2.Select(o => o.Value == "802.11g") != null);
That's not going to do what you want. It's just going to return every item from the input sequence, since m.Object2.Select(...) returns an IEnumerable<T> which is never equal to null .
Try:
var myResults = Object1.Where(m => m.Object2.Any(o => o.Value == "802.11g"));
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|