|
Thats good info, but I really do not want to databind that textbox. I'm binding back to SQl already I just want to give the user an easy way to populate/change the field value. The combo works, but a list box looks much better. I'm making it visilble from a click event.
Thanhks for the info.
|
|
|
|
|
Hi,
you must convert the SelectedItem of the ListBox into the string you need. You can do this by binding it to another property (of your viewmodel) and in the new property's setter, you can transfer the converted string-value to your TextBox.Text-property. Alternatively you must code the SelectionChanged -event of the ListBox.
The type of the SelectedItem depends on the given Items (sounds a bit stupid, I know). If you fill the ListBox at designtime, you will probably have something like
<ListBox ... >
<ListBox.Items>
<ListBoxItem Content="one" />
<ListBoxItem Content="two" />
<ListBoxItem Content="three" />
</ListBox.Items>
</ListBox>
In this case, the SelectedItem is of type ListBoxItem . If you e. g. provide a List<string> as ItemsSource , you get a string as SelectedItem.
As mentioned by Abhinav S you might want to consider using the IsSynchronizedWithCurrentItem property.
Cheers
Jürgen
|
|
|
|
|
Hi All,
Hope you all are good.
I am adding some wrap panels to a list box..
my coding is
for (int i = 0; i < 15; i++)
{
WrapPanel wrp = new WrapPanel();
wrp.Name = "wrp" + i.ToString().Trim();
Label lbl1 = new Label();
lbl1.Content = "Code " + i.ToString().Trim();
Label lbl2 = new Label();
lbl2.Content = "Desc " + i.ToString().Trim();
wrp.Children.Add(lbl1);
wrp.Children.Add(lbl2);
lbOne.Items.Add(wrp); //lbone is source list box
}
so now i have 15 wrap panels in my lisbox.
i need to add the selected items(wrappanel) to other list box (may be destination)
i tried using
lbtwo.items.add(lbone.selecteditem);
but it says that it has some logical parent.
i.e it is already in the first list box lbone and it cannot be added to the new one..
may i know is there solution for this?
can we add liek this?
|
|
|
|
|
There is, and it's a bit gnarly. The good Dr WPF came up with a Conceptual Children article which details how to solve this issue here[^].
"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
|
|
|
|
|
Whoa ... need to ingest that one at some point ...
|
|
|
|
|
Hi experts,
Created one method to export the datagridview data to excel in winforms which is working fine. Now in similar way i wanted to export data from WPF datagrid to excel, i googled it lot but couldn't find relevant solution.
Any help would be appreciated.
Thanks in advance
-Kartheesh
|
|
|
|
|
I have completed an application that looks boring. I can add graphics to my WPF based GUI but what I would like to do is change the entire shape of the GUI itself. The best example I can think of is that of changing skins on a media player... by changing the skins you can change the overall shape of the GUI as well as the placement of the controls. One skin may be an 800 pound guerrilla while another might be a hamburger. I would be able to change it with the click of a button. I can easily place a picture of a guerrilla into my WPF based GUI and place the controls on it but the GUI itself that contains the guerrilla picture still has four straight sides.... I want my GUI to morph into the shape of the primate.
Can someone point me in the right direction?
And to complicate things.... Another idea we have is to place controls on each of the six sides of a cube. Once we have the GUI assume the shape of the cube we would like the user to be able to use their mouse and spin the cube around by clicking and dragging....thus accessing the controls on the other sides. And could we do all that using finger input on a touch sensitive screen? ...
Can someone point me in the right direction on that idea?
Thanks,
Jay
|
|
|
|
|
Hi
I have a Silverlight application calling a WCF service. SimplehttpBinding stuff.
1. Every I make changes to silverlight xaml code, the web.config gets refrshed also.
2. Even if make any changes to web.cofig file, they get overwritten too.
Its as if, some other process is writing these files. Why is that happening? How can I make sure that it does not get overwritten after every compile?
Please advise. THanks
AJ.
Follow your goals, Means will follow you ---Gandhi---
|
|
|
|
|
Which version of Visual Studio you are using there?
Is it only for Silverlight application?
Can you try with a New Project (both Silverlight & ASsP.Net web app)?
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
I am writing my first WPF program for learning purpose. I discovered there is no FolderBrowserDialog. With some search I figured we are supposed to use Microsoft.Win32.OpenFileDialog. Now, I really do not want to use it. So I tried using FolderBrowerDialog through adding reference to the Windows Form dll. Now, when I try the following code, DialogResult is treated as some nullable type (although intellisense shows it as Enum).
if(dlgFolderBrowser.ShowDialog() == DialogResult.(only nullable type options come up))
Any idea how this can be fixed? Or any better solution than using a OpenFileDialog with multiple select option?
|
|
|
|
|
Found this here -
System.Windows.Controls.PrintDialog dlg = new System.Windows.Controls.PrintDialog();
dlg.PageRangeSelection = PageRangeSelection.AllPages;
dlg.UserPageRangeEnabled = true;
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
}
This link, I guess, should give you a solution.
My signature "sucks" today
|
|
|
|
|
Does not works with System.Windows.Forms.FolderBrowserDialog . Its return type is DialogResult and not Nullable.
|
|
|
|
|
this.DialogResult is a property on WPF windows, unrelated to the enum you are looking for. Try to use the fully qualified type name.
|
|
|
|
|
Great! Thanks. I feel stupid to not to be able to figure that out.
BTW, is that a good way? I am not a fan of mixing technologies: WPF and Windows forms in this case.
|
|
|
|
|
There is no List document element in Silverlight 4. So how do you format an itemized list in a RichTextBox? Is there any easy way?
|
|
|
|
|
Hey, What do you mean by itemized list in a RichTextBox?
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
KunalChowdhury wrote: What do you mean by itemized list in a RichTextBox?
I don't understand your question. Surely you aren't asking me what an itemized list is, are you?
It doesn't matter anyhow. There is no way to do it. I just expected it to be there since the new RichTextBox in Silverlight 4 takes a list of something called Paragraph elements and I just naturally assumed these were the same Paragraph elements that were in WPF, which do take itemized lists. But they only vaguely resemble the WPF Paragraph. They don't even have a Margin property which might be a starting point for rolling your own itemized lists.
So forget it. I learned from a recent Code Camp I went to that Microsoft has given up the idea of ever supporting flow documents in Silverlight. Instead in a future release of Silverlight they will provide a way of supporting an HTML area within Silverlight content. (They've always supported the opposite: Silverlight content within HTML.) Once that happens, we'll be able to include itemized lists within Silverlight and the user won't even know or care that it's actually HTML that is generating the itemized list.
I guess Microsoft figured it was easier to rely on existing technology rather than reinventing the wheel. Trouble is, they should have done this ages ago. Meanwhile, we have to wait and wait, and in the meantime put up with poorly formatted running text in Silverlight applications.
The syntax for itemized lists in WPF is incredibly verbose anyhow. It will be a blessing to be able to use the concise syntax of HTML for generating itemized lists, and flow documents in general. The only thing is, it will never have the convenience of automatically flowing into multiple columns like WPF, although I am by no means an HTML programmer, so maybe that will be possible, also.
|
|
|
|
|
The RichTextBox in Silverlight 4 supports the Paragraph element. But if you just put two paragraphs in a row together, there is no leading between the paragraphs. Also, unlike WPF, the Paragraph element does not define a Margin property. If the first paragraph just happens to fill the last line (or nearly so), it looks as if there is only one paragraph and there is no visual clue that you actually have two paragraphs.
So how do you control the leading between paragraphs? You get far too much leading if you end each paragraph with a LineBreak element, so that's not a solution, and it's a kludge to begin with.
Solution: The only way to solve this is through a kludge. I bounced this solution off a Silverlight MVP and he thought this kludge was "clever." To provide leading between each paragraph in the BlockCollection of a RichTextBox, you can include markup like the following:
<Paragraph FontSize="4"></Paragraph>
when for example the font size of your paragraphs is 14. If you use the default font size for your paragraphs (11), a font size of 3 might work in the kludge.
modified on Monday, May 24, 2010 3:36 PM
|
|
|
|
|
Thanks for posting a solution here - even though it's a workaround.
My signature "sucks" today
modified on Tuesday, May 25, 2010 2:17 AM
|
|
|
|
|
I have implemented validation using IDialogService on INotifyPropertyChanged but its not working properly when i click on save button and after successfull insertion if i ll clear my control then also my validation message display error message.
if any boday can help me then i ll be thankfull to him.
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
modified on Saturday, May 22, 2010 5:35 AM
|
|
|
|
|
You need to post code here to show what you have implemented so far before anyone can help you.
My signature "sucks" today
|
|
|
|
|
below is used for binding validation
<TextBox x:Name="txtDispalyName" Text="{Binding Path=DisplayName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}" Grid.Row="1" Height="24" LostFocus="txtDispalyName_LostFocus" Grid.Column="2" Margin="18,2,54,0" VerticalAlignment="Top" TabIndex="0" >
while in code behind on save click i m calling below code
ViewModel.IsError = true;
getBindProperty();
if (ViewModel.Save())
{
IsSaveClose = true;
SaveData();
}
else
{
ViewModel._dialogService.DisplayValidationDialog(ViewModel.Errors);
}
while my validation class is
public class MyViewModel : INotifyPropertyChanged
{
public readonly IDialogService _dialogService;
CultureInfo Culture;
public MyViewModel(IDialogService dialogService)
{
_dialogService = dialogService;
}
private string _displayName = "";
public bool IsError { get; set; }
public string DisplayName
{
get { return _displayName ; }
set
{
if (string.IsNullOrEmpty(value))
{
Culture = Thread.CurrentThread.CurrentCulture;
IsError = false;
throw new Exception(Erp3s.Resources.Strings.ResourceManager.GetString("Display Name is required",Culture));
}
_displayName = value;
OnPropertyChanged("DisplayName");
}
}
private readonly ObservableCollection<ValidationError> _errors = new ObservableCollection<ValidationError>();
public ObservableCollection<ValidationError> Errors
{
get { return _errors; }
}
public bool IsViewStateValid()
{
return Errors.Count == 0;
}
public bool Save()
{
if (!this.IsViewStateValid())
{
return false;
}
else
{
return true;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler pceh = PropertyChanged;
if (pceh != null)
{
pceh(this, new PropertyChangedEventArgs(propertyName));
}
}
}
for reference i had referred http://www.thejoyofcode.com/Silverlight_Validation_and_MVVM_Part_II.aspx[^]
but my problem is when i click on save button and if i will clear my textbox then also this validations are fired.
Reasons are not Important but Results are Important.
http://www.sql4professional.blogspot.com
Swati Tripathi
|
|
|
|
|
Hi,
you might want to consult the help about the VisualTreeHelper class. I think this provides the functionality you're looking for.
If you need further assinstance, please provide some more concrete code/XAML.
Cheers
Jürgen
|
|
|
|
|
Hi,
your problem has nothing to do with WPF; it's about C# fundamentals.
You might want to take a look at the inheritance tree. There you can see why you get that error. Neither Border nor Image derive from Control.
To be honest (really no flaming or insulting intended):
The best advice I can give you, is to take a good book about C#- or .Net basics and a little time.
In case I'm mistaken, I'll give you some clues (which hopefully will only help you if I'm mistaken):
1. ugly solution: use the VisualTreeHelper class.
2. ugly solution: use a common ancestor
3. good solution: use data binding
Both ugly solutions (as well as the provided code) imply that you will never use your own controls - or you'll get an endless list of "if ... GettYpe()". Solution #2 (as well as the provided code) still has to deal with the stacking of WPF objects (you will find the Border inside the Canvas, but you will not find the TextBox inside the Border).
Unfortunately I can't recommend any C# book, but if it's up to WPF (and accordingly data binding), I've learned a lot from "WPF unleashed".
Cheers
Jürgen
|
|
|
|
|
Hema Bairavan wrote: if(ctr.Gettype() == tx.Gettype())
Why dont you just put in a condition to check for and avoid a border .
foreeach(control ctr in OuterCanvas.controls)<br />
if(ctr.Gettype() == tx.Gettype() && ctr.Gettype() != System.Windows.Border)<br />
((TextBox)ctr).text = "";
My signature "sucks" today
|
|
|
|