Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1065409
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T19:47:51+00:00 2026-05-16T19:47:51+00:00

<RichTextBox x:Name=OrigText Margin=0,0,8,0 d:LayoutOverrides=Width/> <Button x:Name=OrigFileBrowse Command={Binding BrowseCommand} CommandParameter={Binding ElementName=OrigText, Path=Document} HorizontalAlignment=Center Margin=0,0,8,2.442 Width=75

  • 0
<RichTextBox x:Name="OrigText" Margin="0,0,8,0" d:LayoutOverrides="Width"/>
    <Button x:Name="OrigFileBrowse" Command="{Binding BrowseCommand}" CommandParameter="{Binding ElementName=OrigText, Path=Document}" HorizontalAlignment="Center" Margin="0,0,8,2.442" Width="75" Content="Browse" Grid.Row="1" d:LayoutOverrides="Height"/>
    <RichTextBox x:Name="ModifiedText" Grid.Column="1" Margin="8,0,0,0"/>
    <Button x:Name="ModifiedFileBrowse" Command="{Binding BrowseCommand}" CommandParameter="{Binding ElementName=ModifiedText, Path=Document}" HorizontalAlignment="Center" Width="75" Content="Browse" Grid.Row="1" Grid.Column="1" Margin="0,0,0,2.442" d:LayoutOverrides="Height"/>
    <Button x:Name="Compare" Command="{Binding CompareCommand}" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75" Content="Compare" Grid.Row="2" Grid.ColumnSpan="2">
        <Button.CommandParameter>
            <x:Array Type="RichTextBox">
                <local:CompareTextView/>
            </x:Array>
        </Button.CommandParameter>
    </Button>

Trying to get 2 items to be passed when the Compare button is clicked as it will then execute a compare command. Attempted to make use of MultiBinding however that is firing on instantiation and therefore the converter then fires accordingly. It does NOT fire when I click compare and the compare command is executed.

With that not working, I am attempting to now reference the controls within XAML to pass within an ArrayExtension. Not sure of the syntax or if it is even possible as I know you cannot bind within the ArrayExtension. The above fails since it can not construct a new CompareTextView view, which has no default constructor since I am making use of Prism…

Pretty frustrating, hopefully someone can help me out…

EDIT:

Want to clear some things up. The issue is not that I want CanExecute called again. The issue is that at instantiation of the controls, the converter is called and executed and the values are returned…but where they go I have no clue? The converter is never called again. If I could get the initial references to the FlowDocument this would all be a moot point…but it doesn’t return things anywhere per se…since this is a command…if that makes sense…when making use of MultiBinding.

        <Button x:Name="Compare" Command="{Binding CompareCommand}" HorizontalAlignment="Center" VerticalAlignment="Top" Width="75" Content="Compare" Grid.Row="2" Grid.ColumnSpan="2">
        <Button.CommandParameter>
            <MultiBinding Converter="{StaticResource FlowDocumentConverter}">
                <Binding ElementName="OrigText" Path="Document"/>
                <Binding ElementName="ModifiedText" Path="Document"/>
            </MultiBinding>
        </Button.CommandParameter>
    </Button>

UPDATE:

Tried what refereejoe mentions here, scroll down a little bit to see his posting. While CanExecute continually fires, this does nothing to resolve the issue. In addition I switched the MultiBinding to be a single item, it is coming back null. Again when the converter fires on instantiation the FlowDocument references are there…

ANSWER:

Abe’s mention that it was being cached led me to try something else. Since I knew that the FlowDocument references were available when the converter was called I knew they were there. Something was getting fouled up. The key piece appears to be in the converter itself. I was simply returning the object[]. Then when the command fired the arg was indeed an object[] but the two items were null. I created a class called Docs, which had two properties, one for each FlowDocument reference. When the converter fired I set the properties appropriately and then returned the Docs object. Now when I initiated the compare command, the Docs object was the args and it had the reference to the FlowDocuments just as I needed! Not sure if this is by design, but the fact that the items get lost when using the object[] doesn’t make sense to me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T19:47:52+00:00Added an answer on May 16, 2026 at 7:47 pm

    The proper way to do this is indeed with a MultiBinding on the CommandParameter. You won’t see it call your CanExecute method unless WPF is informed that the method could return a different value than it had already cached (via the CanExecuteChanged event).

    Since you are relying on the parameter passed in to determine this, we have to raise the event when the parameter changes. Since we can’t really determine that in the command, we can use another technique: tell WPF to poll our command anytime it polls UICommands. This is done by implementing your ICommand like so:

    public class MyCommand : ICommand
    {
        public void Execute(object parameter) { /* do stuff */ }
        public bool CanExecute(object parameter { /* determine if we can do stuff */ }
    
        public event EventHandler CanExecuteChanged
        {
            add { CommandManager.RequerySuggested += value; }
            remove { CommandManager.RequerySuggested -= value; }
        }
    }
    

    Obviously, this prevents you from using the Prism DelegateCommand, but this will respond to changes in the command parameters.

    UPDATE

    Another thing to consider is that the Document property on the RichTextBox isn’t actually changing. Instead, when you type into it, the content of the FlowDocument changes. Since the property instances don’t change, the converter won’t get fired again, and the originally converted value will get stored in the CommandParameter property.

    One of the ways to force the converter to be called again is to add a Binding to the MultiBinding that is bound to a property that will change every time the text of the RichTextBox changes.

    A somewhat hacky solution would be to use the IsKeyboardFocusWithin property, as that will mimic the default binding behavior of TextBox.Text (i.e. when the TextBox loses focus, the Binding updates):

    <MultiBinding Converter="{StaticResource FlowDocumentConverter}">
        <Binding ElementName="OrigText" Path="Document" />
        <Binding ElementName="ModifiedText" Path="Document" />
        <Binding ElementName="OrigText" Path="IsKeyboardFocusWithin" />
        <Binding ElementName="ModifiedText" Path="IsKeyboardFocusWithin" />
    </MultiBinding>
    

    Obviously, in your converter, you will need to ignore these additional values, as they aren’t relevant to your conversion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a RichTextBox (.NET WinForms 3.5) and would like to override some of
For my C# RichTextBox, I want to programmatically do the same thing as clicking
I have a RichTextBox in .NET WinForms. I have been hooking up hot keys
I'm using a RichTextBox in WinForms 3.5 and I found that when I programmatically
I am using a RichTextBox in WPF, and am trying to set the default
We've used the no-longer-supported RichTextBox control as part of our (ASP.NET-based) CMS for a
I'm looking for a good ASP.NET RichTextBox component that integrates fairly easily with .NET
I need to create a simple editor using a RichTextBox control in a windows
I'm using the built-in SpellCheck for the WPF RichTextBox and would like to ignore
I've made a C# usercontrol with one textbox and one richtextbox. How can I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.