Click here to Skip to main content
15,887,683 members
Home / Discussions / WPF
   

WPF

 
AnswerRe: Resize and Edit Text in wpf Pin
Mycroft Holmes8-May-12 12:29
professionalMycroft Holmes8-May-12 12:29 
Questiontry to add data on wpf DataGridColumn Pin
MemberDotNetting7-May-12 10:55
MemberDotNetting7-May-12 10:55 
AnswerRe: try to add data on wpf DataGridColumn Pin
Mycroft Holmes7-May-12 12:26
professionalMycroft Holmes7-May-12 12:26 
AnswerRe: try to add data on wpf DataGridColumn Pin
Wayne Gaylard7-May-12 20:09
professionalWayne Gaylard7-May-12 20:09 
GeneralRe: try to add data on wpf DataGridColumn Pin
MemberDotNetting7-May-12 23:23
MemberDotNetting7-May-12 23:23 
QuestionWPF DataGrid cell click Pin
LAPEC7-May-12 9:27
LAPEC7-May-12 9:27 
Questionwpf ritchbox Pin
MemberDotNetting6-May-12 3:41
MemberDotNetting6-May-12 3:41 
AnswerRe: WPF RichTextBox Pin
Wayne Gaylard6-May-12 21:07
professionalWayne Gaylard6-May-12 21:07 
I don't know how you are populating the ComboBox, but I assume it is in the XAML. In this case the SelectedItem would be a ComboBoxItem which does not implement the IConvertible interface and so cannot be converted to a double. Personally, I would use WPF's binding mechanism to implement this using 2 properties, and ObservableCollection<int> to hold the allowed font sizes, and an int property to hold the selected font size, something like this:-
C#
public ObservableCollection<int> Fonts
{
get
{
    return new ObservableCollection<int>() { 8, 9, 10, 12, 14 };
}
}

int selectedFontSize;
public int SelectedFontSize
{
get
{
    return selectedFontSize;
}
set
{
    if (selectedFontSize != value)
    {
        selectedFontSize = value;
        OnPropertyChanged("SelectedFontSize");
    }
}
}

(this assumes you user control / window implements INotifyPropertyChanged). Then you can just create the bindings in your XAML like this:
XML
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition />
    </Grid.RowDefinitions>
    <ComboBox ItemsSource="{Binding Fonts}" SelectedItem="{Binding SelectedFontSize}" Width="200" HorizontalAlignment="Left"/>
    <RichTextBox Grid.Row="1">
        <FlowDocument FontSize="{Binding SelectedFontSize}">
            <Paragraph >
                Hello World!
            </Paragraph>
        </FlowDocument>
    </RichTextBox>
</Grid>

and that is all there is to it, not forgetting to set the DataContext of your user control / window to itself like this in the constructor:
C#
public MainWindow()
{
    InitializeComponent();
    this.DataContext = this;
}


Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

Questionadd wpf user control Pin
MemberDotNetting4-May-12 22:22
MemberDotNetting4-May-12 22:22 
AnswerRe: add wpf user control Pin
Abhinav S5-May-12 21:40
Abhinav S5-May-12 21:40 
QuestionWPF DataGrid cell click Pin
LAPEC4-May-12 1:06
LAPEC4-May-12 1:06 
AnswerRe: WPF DataGrid cell click Pin
Erik Rude4-May-12 1:31
Erik Rude4-May-12 1:31 
GeneralRe: WPF DataGrid cell click Pin
LAPEC4-May-12 1:51
LAPEC4-May-12 1:51 
GeneralRe: WPF DataGrid cell click Pin
Erik Rude4-May-12 2:46
Erik Rude4-May-12 2:46 
AnswerRe: WPF DataGrid cell click Pin
Jeremy Hutchinson4-May-12 2:46
professionalJeremy Hutchinson4-May-12 2:46 
Questionuser control Pin
MemberDotNetting3-May-12 13:40
MemberDotNetting3-May-12 13:40 
AnswerRe: user control Pin
Jeremy Hutchinson4-May-12 2:34
professionalJeremy Hutchinson4-May-12 2:34 
AnswerRe: user control Pin
Alisaunder6-May-12 2:23
Alisaunder6-May-12 2:23 
QuestionHow to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#3-May-12 4:02
Rocky#3-May-12 4:02 
AnswerRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Jeremy Hutchinson3-May-12 5:30
professionalJeremy Hutchinson3-May-12 5:30 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#3-May-12 20:42
Rocky#3-May-12 20:42 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Jeremy Hutchinson4-May-12 1:48
professionalJeremy Hutchinson4-May-12 1:48 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#4-May-12 3:05
Rocky#4-May-12 3:05 
AnswerRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Mycroft Holmes3-May-12 12:46
professionalMycroft Holmes3-May-12 12:46 
GeneralRe: How to get the value of textbox in ViewModel in WPF - MVVM Pin
Rocky#3-May-12 20:19
Rocky#3-May-12 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.