|
Very new to WPF. Trying to keep things simple. Some of the posts I read were a bit confusing - they assume I know something... Wink
I have a ComboBox that works well; display, etc.
Depending on the item selected from the ComboBox (i.e., 3, 7, or 11), I want the respective data displayed in their own text boxes.
The data:
3, Text1, Nbr1
7, Text2, Nbr2
11, Text3, Nbr3
etc.
<pre> <ComboBox Grid.Row="10" Grid.ColumnSpan="2" Width="160" Height="25" Margin="0,0,0,0"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
FontSize="12" FontWeight="Bold" IsReadOnly="True"
BorderThickness="2" BorderBrush="Black"
Name="cboNewOption" Background="#FFFFB2" HorizontalAlignment="Right"
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>11</ComboBoxItem>
<ComboBoxItem>13</ComboBoxItem>
</ComboBox>
<TextBox Grid.Row="10" Grid.Column="3" Grid.ColumnSpan="2" Width="100" Margin="40,0,10,0"
HorizontalAlignment="Left" VerticalAlignment="Center"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
FontSize="12" FontWeight="Bold" IsReadOnly="True"
Name="txtOne" Background="#FFFFB2" ></TextBox>
<TextBox Grid.Row="10" Grid.Column="3" Grid.ColumnSpan="2" Width="100" Margin="40,0,10,0"
HorizontalAlignment="Left" VerticalAlignment="Center"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
FontSize="12" FontWeight="Bold" IsReadOnly="True"
Name="txtTwo" Background="#FFFFB2" ></TextBox>
</pre>
How do I set up the data/routines so it displays like I want? I would appreciate whatever you care to share!!
Thank you, in advance!
Steve
|
|
|
|
|
Give your combo box a name:
x:Name="myComboBox"
Then bind your textboxes to the combobox using an ElementName type binding.
Text="{Binding ElementName=myComboBox, Path=SelectedItem.PropertyName}"
|
|
|
|
|
Thanks, Jammer.
May I re-iterate? Most posts assume I know something....
I don't know how to set up the data for the textboxes... I have pretty well mastered the visible (design) portion of XAML. Now trying to understand how to put it together with some functionality (real code). I figured out the code behind for a single button-click maneuver. Trying to bind is where my head hurts... The videos I've seen work from a database that is already created - especially those from MSDN. I just have minimal data I need to tie together...
Please?
Again, thanks, in advance!
Steve
|
|
|
|
|
Gotcha.
Put the data you wish to bind too in a collection like:
public ObservableCollection<string> MyData = new ObservableCollection<string>();
Then bind your combobox to this collection like:
<ComboBox Content={Binding MyData} />
This is assuming that the DataContext is set for XAML to the object that contains your MyData collection.
Make sense?
|
|
|
|
|
So-o-o, modifying my initial post...
The data:
3, Text1, Nbr1
7, Text2, Nbr2
11, Text3, Nbr3
etc.
<ComboBox Name="myComboBox"
Content={Binding MyData}
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>7</ComboBoxItem>
<ComboBoxItem>11</ComboBoxItem>
<ComboBoxItem>13</ComboBoxItem>
</ComboBox>
<TextBox Name="txtOne"
Text="{Binding ElementName=myComboBox,
Path=SelectedItem.PropertyName}"</TextBox>
<TextBox Name="txtTwo"
Text="{Binding ElementName=myComboBox,
Path=SelectedItem.PropertyName}"</TextBox>
<TextBox Name='Etc-etc" />
When I only had one number to display, it was easy:
private void btnGenData_Click(object sender, RoutedEventArgs e)
{
txtNewText.Text = "Text1";
txtNewNbr.Text = "Nbr1";
}
Guess I'm now looking at a case statement...?
public ObservableCollection<string> MyData = new ObservableCollection<string>();
private void btnGenPrime_Click(object sender, RoutedEventArgs e)
{
switch (MyData)
{
case 3:
txtNewText.Text = "Text1";
txtNewNbr.Text = "Nbr1";
break;
case 7:
txtNewText.Text = "Text2";
txtNewNbr.Text = "Nbr2";
break;
case 11:
txtNewText.Text = "Text3";
txtNewNbr.Text = "Nbr3";
break;
}
}
I don't care if it's in XAML or codebehind...it is said you can almost do it all in XAML, right?
Sorry for being dense...
Thanks.
< Steve >
|
|
|
|
|
Start a new project then paste this in:
MainWindow.xaml
<Window x:Class="ComboBoxDemo.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource self}}"
Title="MainWindow"
Height="350"
Width="525">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<ComboBox ItemsSource="{Binding MyData}"
DisplayMemberPath="Value1"
SelectedItem="{Binding YourSelectedItem}" Grid.ColumnSpan="3" />
<TextBox Text="{Binding YourSelectedItem.Value1}" Grid.Row="1" />
<TextBox Text="{Binding YourSelectedItem.Value2}" Grid.Row="1" Grid.Column="1" />
<TextBox Text="{Binding YourSelectedItem.Value3}" Grid.Row="1" Grid.Column="2" />
</Grid>
</Window>
Code Behind:
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace ComboBoxDemo
{
public partial class MainWindow : INotifyPropertyChanged
{
public ObservableCollection<MyDataObject> MyData { get; set; }
private MyDataObject yourSelectedItem;
public MyDataObject YourSelectedItem
{
get { return yourSelectedItem; }
set { yourSelectedItem = value; OnPropertyChanged("YourSelectedItem"); }
}
public MainWindow()
{
MyData = new ObservableCollection<MyDataObject>();
InitializeComponent();
AddData(new MyDataObject {Value1 = 1, Value2 = "string 1", Value3 = 1});
AddData(new MyDataObject {Value1 = 2, Value2 = "string 2", Value3 = 2});
AddData(new MyDataObject {Value1 = 3, Value2 = "string 3", Value3 = 3});
}
public void AddData(MyDataObject obj)
{
MyData.Add(obj);
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string info)
{
if(PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
MyDataObject:
namespace ComboBoxDemo
{
public class MyDataObject
{
public int Value1 { get; set; }
public string Value2 { get; set; }
public int Value3 { get; set; }
}
}
|
|
|
|
|
Hi there, this is one of the first posts I've done on a code site so please be gentle, I'll give a quick full overview of the context in which i wish to use the toggle button in a datagrid so hopefully you'll be able to help. Firstly I am developing a database interface through wpf window front-end (i have the database functionality sorted), one condition i thought of in advance was if a user updates a record that has been updated between the time they checked out that a cool way to deal with this issue would be to have a widow popup with a datagrid (with 2 rows and the number of columns in the data) in which each cell shows a rows data within a toggle button and each column can only have one button pressed in at a time, i.e. if a button is pressed, any other pressed button in the same column is depressed. As far as i can see from documentation i've found, i will have to template my own style of toggle button pressed/depressed styles (not sure how to do, also i would ideally like the look of the button to be like a normal button the only difference being that the button isn't depressed until another button is pressed) and i will also have to have my own implementation of a datagridcolumn which somehow (really not sure if this is even possible now) knows which buttons are pressed and if a different button is pressed becomes depressed. That was harder than originally thought. Sorry about the poor description, hope someone gets what I mean.
Thanks for any help in advance!
Chris
|
|
|
|
|
To be honest chap, I'm not even sure there is a question in that post! I think you should break it all down a bit and ask a specific question.
|
|
|
|
|
I'm going to try translating your question, please correct me if I'm wrong.
The Problem:
Two users are editing the same data. User A submits their changes first, and User B follows shortly after. The version that User B edited is now older than what is stored.
The goal is to properly notify User B that there is newer data present, and allow them to merge their changes.
Your Issue:
Your post suggests that you came up with a UI concept to allow a user to easily merge data conflicts, but are having problems implementing your mutually exclusive data-selector-button-thing-a-ma-giggers?
|
|
|
|
|
Hi Experts,
I have a window which is having some objects of a user control. The user control is nothing but a combination of label and textbox. I have set the tabindex property of these objects in certain order but when i run the window that order is not maintained. This is working fine if i use normal wpf controls like the normal textbox or button. Am i missing something?
Please help!
Thanks in advance!
Regards,
Samar
|
|
|
|
|
Hi All,
I am new to WCF. I have created a WCF Service and hosted it in Windows Service. I have got a below Error when tring to create Client Proxy for the service.
Error Message:
"There was an error downloading 'http://localhost:8051/Service1/'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:8051
Metadata contains a reference that cannot be resolved: 'http://localhost:8051/Service1/'.
Could not connect to http://localhost:8051/Service1/. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8051.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:8051
If the service is defined in the current solution, try building the solution and adding the service reference again."
I have seen some posts related to Issue like unblocking the port in Firewall. I have unblocked all ports from Firewall, Still the Issue raising while create Client Proxy. Some one can help me on this Problem. I have Pasted my configuration file below.
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="WcfService1.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" contract="WcfService1.IService1">
</endpoint>
<!--<endpoint address="" binding="netTcpBinding" contract="WcfService1.IService1"></endpoint>-->
<!--<endpoint address="mextcp" binding="mexTcpBinding" contract="IMetadataExchange"/>-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8051/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService1.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Please reply me to solve this problem.
|
|
|
|
|
Do you actually have something running on port 8051 listening for the incoming request? To find out, start up a command session and run the command netstat -a to view the listening ports.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
This might be of some use to you.
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.
|
|
|
|
|
Hi All,
I've never done anything along these lines before and I'm struggling a bit with the implementation.
I have a graphical selector and I have the mousedown and mouseup points as the definition for a selected area in the UI. What I need to then do is work out which controls are within the selection point and set them as selected.
Anyone have any info or links on how to implement this?
TIA,
|
|
|
|
|
As you are aware, it can seem pretty tricky to work out what the location of a control is in WPF space because the margin relates to the parent of the control which may or may not be the window. What you could do is something like this:
private Point GetElementLocation<T>(Window window, T control) where T : UIElement
{
GeneralTransform xform = control.TransformToAncestor(window);
return xform.Transform(new Point(0,0));
} This gives you the co-ordinates of the top-left of the control. From here, it's fairly simple to work out how big a control is by adding the Width and Height in, which gives you the rectangle that represents your control. Now, it's a simple matter to just check the bounds of each control and see if it falls inside your selection rectangle (note that this is a rough test only, as it really only caters for rectangular shapes - it's entirely possible that a circle doesn't fall within the bounds for instance).
Note that an alternative to TransformToAncestor is to use the following:
private Point GetElementLocation<T>(Window window, T control) where T : UIElement
{
Vector vector = VisualTreeHelper.GetOffsetAt(control);
return new Point(vector.X, vector.Y);
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Thanks for this Pete. Off to have a play with this now. What I had up to this point was:
Rect selectionRect = new Rect(_mouseDownPos, mouseUpPos);
foreach (var editor in Editors)
{
var bounds = VisualTreeHelper.GetDescendantBounds(editor);
if (selectionRect.IntersectsWith(bounds))
{
editor.IsSelected = true;
}
else
{
editor.IsSelected = false;
}
}
This is sort of working but it's far from correct at the moment.
Thanks,
|
|
|
|
|
Awesome Pete ... got it licked in no time thanks to your help! Much appreciated chap.
|
|
|
|
|
Glad I could help mate.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi I've been doing WPF for a while now and am unsure of the best way to approach something so am asking here to see if you guys can help.
Basically I want to use a WPF frame to display multiple pages in one window. However I want to edit the existing frame somewhat.
I know there is a Back and Forward button that can be used with the frame, however I would like some more functionality, like for example a Home button. So to my question whould it be best to:
Create a custom control/ user control using the frame for the basica navigation for back & forward
Or Edit the exisiting Frame template and add the extra button creating my own styles for all the buttons Back/Forward and Home. (if possible)
Or Use a frame with out the header and then create seperate buttons on the screen that hock into the navigation of the Frame to do back and forward.
Thank you in advance for you advice on this matter.
Gretna
Some people are like slinky's... They're not really good for anything but they bring a smile to your face when pushed down the stairs
|
|
|
|
|
Hai all ,
Can anyone help me how to print page number in XamReportPreview.
Thank you
|
|
|
|
|
Hello
I'm using CodePlex WPF ComboBox and is having trouble pre-select item
From code behind, I bind the combo box to a DataTable with two columns:
<br />
...<br />
SomeTableSrc = new DataTable("SomeData");<br />
SomeTableSrc.Columns.Add("Data", typeof(string));<br />
SomeTableSrc.Columns.Add("IsSelected", typeof(bool));<br />
lstSomeData.DataContext = SomeTableSrc.DefaultView;<br />
Xaml:
<combobox name="lstSomeData">
<combobox.itemcontainerstyle itemssource="{Binding}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
The above will select relevant "ComboBoxItem" (and it works fine, if you click on ComboBox, as menu expands you can see desired items actually get selected), *** BUT *** "SelectedValue" or "Text" of "ComboBox" (not items) remains blank - and setting these "ComboBox" attributes directly just don't work.
<br />
lstSomeData.SelectedValue = "ABC";<br />
<br />
lstSomeData.Text = "ABC"; <br />
And I've already tried (PreSelectedData = code behind attrib hardcoded to return string "ABC"):
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="{Binding PreSelectedData}" SelectedValue="{Binding PreSelectedData}">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
Or even outright hardcode,
<ComboBox.ItemContainerStyle ItemsSource={Binding} Text="ABC" SelectedValue="ABC">
<Style TargetType="{x:Type ComboBoxItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected}" />
</Style>
</ComboBox.ItemContainerStyle>
</ComboBox>
No luck!
dev
modified on Wednesday, July 7, 2010 10:23 PM
|
|
|
|
|
I am building a fairly large network of agents and 'mothership' servers.
I'm writing a WPF application which will connect to each mother and either configure/manage/view it's agents.
I can have a large collection of mother's out there.
What I want to do is keep client configurations in the config file.
In the program I want to be able to scan the clients and for each endpoint build up a list of endpoint names.
This way the consumer of the program can select a mother, then run requests against that service.
It looks as if ConfigurationManager.GetSection() might do the trick, but it only returns an object.
Has anyone written code to walk the list of client endpoints to build a list?
Any help appreciated
|
|
|
|
|
Ok I'm trying to see what is missing from my system that seems to be giving problems whilst trying to build this program. The program is Groceries Shopping Helper off of Codeplex.[^]
I made modifications to the main project in the solution but the web product seems to be giving me problems. I found this link: [^] and it helped get the client going but Groceries.web is still showing the following missing:
1) System.Web.DomainServices (According to link should be: System.ServiceModel.DomainServices.Server)
2) System.Web.RIA (System.ServiceModel.DomainServices.Server)
Now when I go in to add a reference I can see System.ServiceModel and System.ServiceModel.Web but none that have DomainServices in their name. This leaves me perplexed, hornswoggled and all those other words as far as what pieces I need to add to my system for this.
I have installed currently Silverlight 4, the Control Toolkit, WCF RIA Services and the WCR RIA Services Toolkit. (Toolkit is May edition, all of these have been installed in the last week).
So any help that anyone can give me will be much appreciated as I'm trying to actually get some things done. LOL.
Thanks Christopher
P.S.: One addendum that may help. I just tried to add a new item and had no entry for ADO.NET Entity Data Model wizard. I am running on Win 7 and using Visual Studio 10 Ultimate.
|
|
|
|
|
Hi All,
Does anyone know of any resource online that talks about this kind of functionality? I'd like to be able to select a range of controls in the UI using the mouse but showing a lasso as the user drags over the UI.
Cheers,
|
|
|
|
|
The first result for lasso.
|
|
|
|