Read barcode which has control characters/invisible characters in it.(using c# and wpf)












0















Requirement:-
To create a Windows application to read barcode which has control characters/invisible characters in it.(using c# and wpf)



I have attached a sample solution which I tried but I have the following issue:-



The solution works fine for barcode without control characters and also for barcodes having ESC or Enter as control characters.
But for control characters like [TAB] , [SHIFT] , [DEL] ,[BACKSPACE] it doesn’t works correctly.



For example:-



If I manually put : 1234[ALT]009[RELEASE ALT]5678[ENTER]: simulates the invisible character
But if I try reading the same via bar code(see attachment for bar code) the entire things gets cleared out. (Check in sample solution)
When I tried to figure out the reason on my end, I found ‘PreviewTextInput’ event is not raised for the invisible character(tab control).



Please can anyone suggest an alternative solution or what changes to be made in the solution I shared so
that I achieve the functionality required.



Sample Solution and Barcode uploaded



Thanks in advance!










share|improve this question























  • Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

    – Fildor
    Nov 15 '18 at 8:25


















0















Requirement:-
To create a Windows application to read barcode which has control characters/invisible characters in it.(using c# and wpf)



I have attached a sample solution which I tried but I have the following issue:-



The solution works fine for barcode without control characters and also for barcodes having ESC or Enter as control characters.
But for control characters like [TAB] , [SHIFT] , [DEL] ,[BACKSPACE] it doesn’t works correctly.



For example:-



If I manually put : 1234[ALT]009[RELEASE ALT]5678[ENTER]: simulates the invisible character
But if I try reading the same via bar code(see attachment for bar code) the entire things gets cleared out. (Check in sample solution)
When I tried to figure out the reason on my end, I found ‘PreviewTextInput’ event is not raised for the invisible character(tab control).



Please can anyone suggest an alternative solution or what changes to be made in the solution I shared so
that I achieve the functionality required.



Sample Solution and Barcode uploaded



Thanks in advance!










share|improve this question























  • Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

    – Fildor
    Nov 15 '18 at 8:25
















0












0








0








Requirement:-
To create a Windows application to read barcode which has control characters/invisible characters in it.(using c# and wpf)



I have attached a sample solution which I tried but I have the following issue:-



The solution works fine for barcode without control characters and also for barcodes having ESC or Enter as control characters.
But for control characters like [TAB] , [SHIFT] , [DEL] ,[BACKSPACE] it doesn’t works correctly.



For example:-



If I manually put : 1234[ALT]009[RELEASE ALT]5678[ENTER]: simulates the invisible character
But if I try reading the same via bar code(see attachment for bar code) the entire things gets cleared out. (Check in sample solution)
When I tried to figure out the reason on my end, I found ‘PreviewTextInput’ event is not raised for the invisible character(tab control).



Please can anyone suggest an alternative solution or what changes to be made in the solution I shared so
that I achieve the functionality required.



Sample Solution and Barcode uploaded



Thanks in advance!










share|improve this question














Requirement:-
To create a Windows application to read barcode which has control characters/invisible characters in it.(using c# and wpf)



I have attached a sample solution which I tried but I have the following issue:-



The solution works fine for barcode without control characters and also for barcodes having ESC or Enter as control characters.
But for control characters like [TAB] , [SHIFT] , [DEL] ,[BACKSPACE] it doesn’t works correctly.



For example:-



If I manually put : 1234[ALT]009[RELEASE ALT]5678[ENTER]: simulates the invisible character
But if I try reading the same via bar code(see attachment for bar code) the entire things gets cleared out. (Check in sample solution)
When I tried to figure out the reason on my end, I found ‘PreviewTextInput’ event is not raised for the invisible character(tab control).



Please can anyone suggest an alternative solution or what changes to be made in the solution I shared so
that I achieve the functionality required.



Sample Solution and Barcode uploaded



Thanks in advance!







c# wpf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 5:13









XsysysXsysys

1




1













  • Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

    – Fildor
    Nov 15 '18 at 8:25





















  • Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

    – Fildor
    Nov 15 '18 at 8:25



















Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

– Fildor
Nov 15 '18 at 8:25







Can you specify what kind of barcode? There are plenty of standards. Not all of them can encode just any character set.

– Fildor
Nov 15 '18 at 8:25














1 Answer
1






active

oldest

votes


















0














Your TextBox does not accept Tabs use



AcceptsTab="True"


to make it accept this instead jump to next tabstop. In WPF it is better to use Binding instead CodeBehind, so I created a ViewModel for you handling the Input.



So as first step I created a ViewModel for you:



public class ViewModel: INotifyPropertyChanged
{
private String _inputText;
private ObservableCollection<String> _resultList = new ObservableCollection<string>();
private String _resultText;

public string InputText
{
get => _inputText;
set
{
if (value == _inputText) return;
_inputText = value;
ProcessInput();
OnPropertyChanged();
}
}

private void ProcessInput()
{
ResultList.Clear();
ResultText = GetUiFriendlyBarCode(InputText);
}

public ObservableCollection<string> ResultList
{
get => _resultList;
set
{
if (Equals(value, _resultList)) return;
_resultList = value;
OnPropertyChanged();
}
}

public string ResultText
{
get => _resultText;
set
{
if (value == _resultText) return;
_resultText = value;
OnPropertyChanged();
}
}


private string GetUiFriendlyBarCode(String input)
{
StringBuilder barCodeToDisplay = new StringBuilder();
foreach (char character in input.ToString())
{
var uiFriendlyCharCode = GetUiFriendlyCharCode((int)character);
barCodeToDisplay.Append(uiFriendlyCharCode);
ResultList.Add(uiFriendlyCharCode);
}
return barCodeToDisplay.ToString();
}

//... implement GetUiFriendlyCharCode and INotifyPropertyChnaged


Add the Bindings in Xaml



    <Label Target="{Binding ElementName=Scan}">_Scan</Label>
<TextBox AcceptsTab="True" Grid.Column="1" x:Name="Scan" Height="50" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<!-- List all characters separately -->
<ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="Log" ItemsSource="{Binding ResultList}"/>
<!--
Show a string to the user that clearly shows any invisible characters.
-->
<TextBlock Grid.Row="3">Result</TextBlock>
<TextBox Grid.Row="3" Grid.Column="1" x:Name="Result" Text="{Binding ResultText}"/>


And than add the DataSource in MainWindow



public MainWindow()
{
InitializeComponent();
DataContext = new ViewModel();
}





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312843%2fread-barcode-which-has-control-characters-invisible-characters-in-it-using-c-sh%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your TextBox does not accept Tabs use



    AcceptsTab="True"


    to make it accept this instead jump to next tabstop. In WPF it is better to use Binding instead CodeBehind, so I created a ViewModel for you handling the Input.



    So as first step I created a ViewModel for you:



    public class ViewModel: INotifyPropertyChanged
    {
    private String _inputText;
    private ObservableCollection<String> _resultList = new ObservableCollection<string>();
    private String _resultText;

    public string InputText
    {
    get => _inputText;
    set
    {
    if (value == _inputText) return;
    _inputText = value;
    ProcessInput();
    OnPropertyChanged();
    }
    }

    private void ProcessInput()
    {
    ResultList.Clear();
    ResultText = GetUiFriendlyBarCode(InputText);
    }

    public ObservableCollection<string> ResultList
    {
    get => _resultList;
    set
    {
    if (Equals(value, _resultList)) return;
    _resultList = value;
    OnPropertyChanged();
    }
    }

    public string ResultText
    {
    get => _resultText;
    set
    {
    if (value == _resultText) return;
    _resultText = value;
    OnPropertyChanged();
    }
    }


    private string GetUiFriendlyBarCode(String input)
    {
    StringBuilder barCodeToDisplay = new StringBuilder();
    foreach (char character in input.ToString())
    {
    var uiFriendlyCharCode = GetUiFriendlyCharCode((int)character);
    barCodeToDisplay.Append(uiFriendlyCharCode);
    ResultList.Add(uiFriendlyCharCode);
    }
    return barCodeToDisplay.ToString();
    }

    //... implement GetUiFriendlyCharCode and INotifyPropertyChnaged


    Add the Bindings in Xaml



        <Label Target="{Binding ElementName=Scan}">_Scan</Label>
    <TextBox AcceptsTab="True" Grid.Column="1" x:Name="Scan" Height="50" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

    <!-- List all characters separately -->
    <ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="Log" ItemsSource="{Binding ResultList}"/>
    <!--
    Show a string to the user that clearly shows any invisible characters.
    -->
    <TextBlock Grid.Row="3">Result</TextBlock>
    <TextBox Grid.Row="3" Grid.Column="1" x:Name="Result" Text="{Binding ResultText}"/>


    And than add the DataSource in MainWindow



    public MainWindow()
    {
    InitializeComponent();
    DataContext = new ViewModel();
    }





    share|improve this answer






























      0














      Your TextBox does not accept Tabs use



      AcceptsTab="True"


      to make it accept this instead jump to next tabstop. In WPF it is better to use Binding instead CodeBehind, so I created a ViewModel for you handling the Input.



      So as first step I created a ViewModel for you:



      public class ViewModel: INotifyPropertyChanged
      {
      private String _inputText;
      private ObservableCollection<String> _resultList = new ObservableCollection<string>();
      private String _resultText;

      public string InputText
      {
      get => _inputText;
      set
      {
      if (value == _inputText) return;
      _inputText = value;
      ProcessInput();
      OnPropertyChanged();
      }
      }

      private void ProcessInput()
      {
      ResultList.Clear();
      ResultText = GetUiFriendlyBarCode(InputText);
      }

      public ObservableCollection<string> ResultList
      {
      get => _resultList;
      set
      {
      if (Equals(value, _resultList)) return;
      _resultList = value;
      OnPropertyChanged();
      }
      }

      public string ResultText
      {
      get => _resultText;
      set
      {
      if (value == _resultText) return;
      _resultText = value;
      OnPropertyChanged();
      }
      }


      private string GetUiFriendlyBarCode(String input)
      {
      StringBuilder barCodeToDisplay = new StringBuilder();
      foreach (char character in input.ToString())
      {
      var uiFriendlyCharCode = GetUiFriendlyCharCode((int)character);
      barCodeToDisplay.Append(uiFriendlyCharCode);
      ResultList.Add(uiFriendlyCharCode);
      }
      return barCodeToDisplay.ToString();
      }

      //... implement GetUiFriendlyCharCode and INotifyPropertyChnaged


      Add the Bindings in Xaml



          <Label Target="{Binding ElementName=Scan}">_Scan</Label>
      <TextBox AcceptsTab="True" Grid.Column="1" x:Name="Scan" Height="50" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

      <!-- List all characters separately -->
      <ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="Log" ItemsSource="{Binding ResultList}"/>
      <!--
      Show a string to the user that clearly shows any invisible characters.
      -->
      <TextBlock Grid.Row="3">Result</TextBlock>
      <TextBox Grid.Row="3" Grid.Column="1" x:Name="Result" Text="{Binding ResultText}"/>


      And than add the DataSource in MainWindow



      public MainWindow()
      {
      InitializeComponent();
      DataContext = new ViewModel();
      }





      share|improve this answer




























        0












        0








        0







        Your TextBox does not accept Tabs use



        AcceptsTab="True"


        to make it accept this instead jump to next tabstop. In WPF it is better to use Binding instead CodeBehind, so I created a ViewModel for you handling the Input.



        So as first step I created a ViewModel for you:



        public class ViewModel: INotifyPropertyChanged
        {
        private String _inputText;
        private ObservableCollection<String> _resultList = new ObservableCollection<string>();
        private String _resultText;

        public string InputText
        {
        get => _inputText;
        set
        {
        if (value == _inputText) return;
        _inputText = value;
        ProcessInput();
        OnPropertyChanged();
        }
        }

        private void ProcessInput()
        {
        ResultList.Clear();
        ResultText = GetUiFriendlyBarCode(InputText);
        }

        public ObservableCollection<string> ResultList
        {
        get => _resultList;
        set
        {
        if (Equals(value, _resultList)) return;
        _resultList = value;
        OnPropertyChanged();
        }
        }

        public string ResultText
        {
        get => _resultText;
        set
        {
        if (value == _resultText) return;
        _resultText = value;
        OnPropertyChanged();
        }
        }


        private string GetUiFriendlyBarCode(String input)
        {
        StringBuilder barCodeToDisplay = new StringBuilder();
        foreach (char character in input.ToString())
        {
        var uiFriendlyCharCode = GetUiFriendlyCharCode((int)character);
        barCodeToDisplay.Append(uiFriendlyCharCode);
        ResultList.Add(uiFriendlyCharCode);
        }
        return barCodeToDisplay.ToString();
        }

        //... implement GetUiFriendlyCharCode and INotifyPropertyChnaged


        Add the Bindings in Xaml



            <Label Target="{Binding ElementName=Scan}">_Scan</Label>
        <TextBox AcceptsTab="True" Grid.Column="1" x:Name="Scan" Height="50" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

        <!-- List all characters separately -->
        <ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="Log" ItemsSource="{Binding ResultList}"/>
        <!--
        Show a string to the user that clearly shows any invisible characters.
        -->
        <TextBlock Grid.Row="3">Result</TextBlock>
        <TextBox Grid.Row="3" Grid.Column="1" x:Name="Result" Text="{Binding ResultText}"/>


        And than add the DataSource in MainWindow



        public MainWindow()
        {
        InitializeComponent();
        DataContext = new ViewModel();
        }





        share|improve this answer















        Your TextBox does not accept Tabs use



        AcceptsTab="True"


        to make it accept this instead jump to next tabstop. In WPF it is better to use Binding instead CodeBehind, so I created a ViewModel for you handling the Input.



        So as first step I created a ViewModel for you:



        public class ViewModel: INotifyPropertyChanged
        {
        private String _inputText;
        private ObservableCollection<String> _resultList = new ObservableCollection<string>();
        private String _resultText;

        public string InputText
        {
        get => _inputText;
        set
        {
        if (value == _inputText) return;
        _inputText = value;
        ProcessInput();
        OnPropertyChanged();
        }
        }

        private void ProcessInput()
        {
        ResultList.Clear();
        ResultText = GetUiFriendlyBarCode(InputText);
        }

        public ObservableCollection<string> ResultList
        {
        get => _resultList;
        set
        {
        if (Equals(value, _resultList)) return;
        _resultList = value;
        OnPropertyChanged();
        }
        }

        public string ResultText
        {
        get => _resultText;
        set
        {
        if (value == _resultText) return;
        _resultText = value;
        OnPropertyChanged();
        }
        }


        private string GetUiFriendlyBarCode(String input)
        {
        StringBuilder barCodeToDisplay = new StringBuilder();
        foreach (char character in input.ToString())
        {
        var uiFriendlyCharCode = GetUiFriendlyCharCode((int)character);
        barCodeToDisplay.Append(uiFriendlyCharCode);
        ResultList.Add(uiFriendlyCharCode);
        }
        return barCodeToDisplay.ToString();
        }

        //... implement GetUiFriendlyCharCode and INotifyPropertyChnaged


        Add the Bindings in Xaml



            <Label Target="{Binding ElementName=Scan}">_Scan</Label>
        <TextBox AcceptsTab="True" Grid.Column="1" x:Name="Scan" Height="50" Text="{Binding InputText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

        <!-- List all characters separately -->
        <ListBox Grid.Row="2" Grid.ColumnSpan="2" x:Name="Log" ItemsSource="{Binding ResultList}"/>
        <!--
        Show a string to the user that clearly shows any invisible characters.
        -->
        <TextBlock Grid.Row="3">Result</TextBlock>
        <TextBox Grid.Row="3" Grid.Column="1" x:Name="Result" Text="{Binding ResultText}"/>


        And than add the DataSource in MainWindow



        public MainWindow()
        {
        InitializeComponent();
        DataContext = new ViewModel();
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 '18 at 8:24









        Fildor

        7,16732246




        7,16732246










        answered Nov 15 '18 at 7:55









        Daniel W.Daniel W.

        226111




        226111
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53312843%2fread-barcode-which-has-control-characters-invisible-characters-in-it-using-c-sh%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine