Rotate TextBlock /!\ Resize not suported

This commit is contained in:
adri 2019-01-25 18:25:04 +01:00
parent 5d10cef466
commit 13d7fe2a01
2 changed files with 355 additions and 0 deletions

View File

@ -0,0 +1,268 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F8032333-16C0-49D9-A5F6-D64E6044A580}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>ProjetTheAlone</RootNamespace>
<AssemblyName>ProjetTheAlone</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<Compile Include="Config\Settings2.Designer.cs">
<DependentUpon>Settings2.settings</DependentUpon>
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Converter\BinaryImageConverter.cs" />
<Compile Include="Outil\picToByteArray.cs" />
<Compile Include="Outil\toByteArray.cs" />
<Compile Include="Outil\toNullableByteArray.cs" />
<Compile Include="ViewModel\EncodeEquipe.cs" />
<Compile Include="ViewModel\EncodeEvent.cs" />
<Compile Include="ViewModel\EncodeLieu.cs" />
<Compile Include="ViewModel\EncodeRepas.cs" />
<Compile Include="ViewModel\EncodeTypeEvent.cs" />
<Compile Include="ViewModel\EncodePlats.cs" />
<Compile Include="ViewModel\TextDefilant.cs" />
<Compile Include="ViewModel\VM_DashBoard.cs" />
<Compile Include="View\FicDetailEvent.xaml.cs">
<DependentUpon>FicDetailEvent.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicEncodePlat.xaml.cs">
<DependentUpon>FicEncodePlat.xaml</DependentUpon>
</Compile>
<Compile Include="Model\A_Base.cs" />
<Compile Include="Model\A_T_beneficiaire.cs" />
<Compile Include="Model\A_T_equipe.cs" />
<Compile Include="Model\A_T_event.cs" />
<Compile Include="Model\A_T_lieu.cs" />
<Compile Include="Model\A_T_listParticipant.cs" />
<Compile Include="Model\A_T_listPlat.cs" />
<Compile Include="Model\A_T_plat.cs" />
<Compile Include="Model\A_T_repa.cs" />
<Compile Include="Model\A_T_typeEvenement.cs" />
<Compile Include="Model\A_T_typePlat.cs" />
<Compile Include="Model\A_T_typeRepa.cs" />
<Compile Include="Model\C_T_beneficiaire.cs" />
<Compile Include="Model\C_T_equipe.cs" />
<Compile Include="Model\C_T_event.cs" />
<Compile Include="Model\C_T_lieu.cs" />
<Compile Include="Model\C_T_listParticipant.cs" />
<Compile Include="Model\C_T_listPlat.cs" />
<Compile Include="Model\C_T_plat.cs" />
<Compile Include="Model\C_T_repa.cs" />
<Compile Include="Model\C_T_typeEvenement.cs" />
<Compile Include="Model\C_T_typePlat.cs" />
<Compile Include="Model\C_T_typeRepa.cs" />
<Compile Include="Config\Settings1.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings1.settings</DependentUpon>
</Compile>
<Compile Include="ViewModel\EncodeBeneficiaire.cs" />
<Compile Include="ViewModel\EventPasseModel.cs" />
<Compile Include="Model\G_Base.cs" />
<Compile Include="Model\G_T_beneficiaire.cs" />
<Compile Include="Model\G_T_equipe.cs" />
<Compile Include="Model\G_T_event.cs" />
<Compile Include="Model\G_T_lieu.cs" />
<Compile Include="Model\G_T_listParticipant.cs" />
<Compile Include="Model\G_T_listPlat.cs" />
<Compile Include="Model\G_T_plat.cs" />
<Compile Include="Model\G_T_repa.cs" />
<Compile Include="Model\G_T_typeEvenement.cs" />
<Compile Include="Model\G_T_typePlat.cs" />
<Compile Include="Model\G_T_typeRepa.cs" />
<Compile Include="ViewModel\RepaModel.cs" />
<Compile Include="UserControlDIY\EventFutur.xaml.cs">
<DependentUpon>EventFutur.xaml</DependentUpon>
</Compile>
<Compile Include="UserControlDIY\EventPasse.xaml.cs">
<DependentUpon>EventPasse.xaml</DependentUpon>
</Compile>
<Compile Include="UserControlDIY\Plat.xaml.cs">
<DependentUpon>Plat.xaml</DependentUpon>
</Compile>
<Compile Include="UserControlDIY\Repa.xaml.cs">
<DependentUpon>Repa.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModel\Base.cs" />
<Compile Include="View\Accueil.xaml.cs">
<DependentUpon>Accueil.xaml</DependentUpon>
</Compile>
<Compile Include="View\DashBoard.xaml.cs">
<DependentUpon>DashBoard.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicBeneficiaireEncode.xaml.cs">
<DependentUpon>FicBeneficiaireEncode.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicEncodage.xaml.cs">
<DependentUpon>FicEncodage.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicEvenementEncode.xaml.cs">
<DependentUpon>FicEvenementEncode.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicNewEquipe.xaml.cs">
<DependentUpon>FicNewEquipe.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicNewLieu.xaml.cs">
<DependentUpon>FicNewLieu.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicNewtypeEvent.xaml.cs">
<DependentUpon>FicNewtypeEvent.xaml</DependentUpon>
</Compile>
<Compile Include="View\FicRepasEncode.xaml.cs">
<DependentUpon>FicRepasEncode.xaml</DependentUpon>
</Compile>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="MainWindow.xaml.cs">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="Config\Settings2.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings2.Designer.cs</LastGenOutput>
</None>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<None Include="Config\Settings1.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings1.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Visible>False</Visible>
<ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Content Include="ProjetThe.mdf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="ProjetThe_log.ldf">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<DependentUpon>ProjetThe.mdf</DependentUpon>
</Content>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<ReferencePath Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll" />
<ReferencePath Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\packages\MaterialDesignColors.1.1.1\lib\net45\MaterialDesignColors.dll" />
<ReferencePath Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\packages\MaterialDesignThemes.2.5.0.1205\lib\net45\MaterialDesignThemes.Wpf.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\Microsoft.CSharp.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationCore.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\PresentationFramework.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.DataSetExtensions.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Net.Http.dll" />
<ReferencePath Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xaml.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.Linq.dll" />
<ReferencePath Include="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\WindowsBase.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicDetailEvent.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicEncodePlat.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\MainWindow.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\UserControlDIY\EventFutur.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\UserControlDIY\EventPasse.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\UserControlDIY\Plat.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\UserControlDIY\Repa.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\Accueil.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\DashBoard.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicBeneficiaireEncode.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicEncodage.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicEvenementEncode.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicNewEquipe.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicNewLieu.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicNewtypeEvent.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\View\FicRepasEncode.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\App.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\ProjetTheAlone_Content.g.cs" />
<Compile Include="C:\Users\adrie\OneDrive - Haute Ecole de la ville de Liège\3is\poo\ProjetTheAlone - Copie (9)\ProjetTheAlone\obj\Debug\GeneratedInternalTypeHelper.g.cs" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ProjetTheAlone.ViewModel
{
class TextDefilant : BasePropriete
{
Timer aTimer;
TextBlock textContainer;
char[] textAfficherBuffer;
public string TextAfficher { set => fillBuffer(value); get { return new string(textAfficherBuffer); } }
public TextDefilant(TextBlock tb, string text, int timeMs)
{
this.textContainer = tb;
TextAfficher = text;
SetTimer(timeMs);
aTimer.Enabled = true;
}
private void SetTimer(int timeMs)
{
// Create a timer with a two second interval.
aTimer = new System.Timers.Timer(timeMs);
// Hook up the Elapsed event for the timer.
aTimer.Elapsed += OnTimedEvent;
aTimer.AutoReset = true;
}
private void OnTimedEvent(Object source, ElapsedEventArgs e)
{
textAfficherBuffer = RotateChar(textAfficherBuffer);
OnPropertyChanged("TextAfficher");
}
private void fillBuffer(string text)
{
char[] charToTrim = { '\r', '\n' };
text = text.Trim(charToTrim);
double WTB = textContainer.ActualWidth; //With of textBlock container
double WT = MeasureString(text).Width; //With of Text
double WS = MeasureString(" ").Width; //With of whiteSpace
int nbSp = (int)Math.Ceiling((WTB - WT) / WS); //number of space need to fill textBlock
char[] spText = new string(' ', nbSp).ToCharArray();
this.textAfficherBuffer = new char[nbSp + text.ToCharArray().Length];
Array.Copy(text.ToCharArray(), 0, this.textAfficherBuffer, 0, text.Length);
Array.Copy(spText, 0, this.textAfficherBuffer, text.Length, spText.Length);
}
private char[] RotateChar(char[] txt)
{
char[] oldTxt = txt;
char[] newTxt = new char[oldTxt.Length];
char fc = txt[0];
for (int i = oldTxt.Length - 1; i > 0; i--)
newTxt[((i+1)%oldTxt.Length)] = oldTxt[i];
newTxt[1] = fc;
return newTxt;
}
//https://stackoverflow.com/questions/9264398/how-to-calculate-wpf-textblock-width-for-its-known-font-size-and-characters
private Size MeasureString(string candidate)
{
var formattedText = new FormattedText(
candidate,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(this.textContainer.FontFamily, this.textContainer.FontStyle, this.textContainer.FontWeight, this.textContainer.FontStretch),
this.textContainer.FontSize,
Brushes.Black,
new NumberSubstitution(), (TextFormattingMode)1);
return new Size(formattedText.WidthIncludingTrailingWhitespace, formattedText.Height);
}
}
}